Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
type Node struct {
	cost int
	done bool
}

type Edge struct {
	to, cost int
}

const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	nodes := make([]Node, N)
	for i := 0; i < N; i++ {
		nodes[i].cost = INF
	}
	E := make([][]Edge, N)
	for i := 0; i < N; i++ {
		id, k := sc.nextInt(), sc.nextInt()
		for j := 0; j < k; j++ {
			to, cost := sc.nextInt(), sc.nextInt()
			E[id] = append(E[id], Edge{to, cost})
		}
	}
	nodes[0].cost = 0
	for {
		cur := 0
		minCost := INF
		for i := 0; i < N; i++ {
			n := nodes[i]
			if !n.done && n.cost < minCost {
				cur = i
				minCost = n.cost
			}
		}
		if minCost == INF {
			break
		}
		nodes[cur].done = true
		for i := 0; i < len(E[cur]); i++ {
			to, cost := E[cur][i].to, E[cur][i].cost+nodes[cur].cost
			if !nodes[to].done && cost < nodes[to].cost {
				nodes[to].cost = cost
			}
		}
	}

	for i := 0; i < N; i++ {
		fmt.Fprintln(wtr, i, nodes[i].cost)
	}
	wtr.Flush()
}

C++: #include<bits/stdc++.h>
using namespace std;

typedef pair< int, int > Pi;
struct edge{
  int to, cost;
};
typedef vector< vector< edge > > Graph;

int Dijkstra(Graph& info, int s, int g,
             vector< int >& min_cost) {
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  min_cost.resize(info.size(), -1);
  que.push( Pi( 0, s));
  min_cost[s] = 0;
  while(!que.empty()){
    Pi p = que.top(); que.pop();
    if(p.second == g) return p.first;
    if(p.first > min_cost[p.second]) continue;
    for(int i = 0; i < info[p.second].size(); i++){
      edge& e = info[p.second][i];
      if(min_cost[e.to] == -1 ||
         p.first + e.cost < min_cost[e.to]){
        min_cost[e.to] = p.first + e.cost;
        que.push( Pi( min_cost[e.to], e.to));
      }
    }
  }
  return -1;
}
int main(){
  int n;
  cin >> n;
  Graph graph(n);
  vector< int > min_cost;
  for(int i = 0; i < n; i++){
    int u, k;
    cin >> u >> k;
    for(int i = 0; i < k; i++){
      int c, v;
      cin >> v >> c;
      graph[u].push_back( (edge){ v, c});
    }
  }
  Dijkstra( graph, 0, n, min_cost);
  for(int i = 0; i < n; i++){
    cout << i << " " << min_cost[i] << endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;

const int INF = numeric_limits<int>::max();

struct edge {
    int u, v, c;
};
struct Graph {
    vector<edge> es;
    vector<int> d;
    Graph(int n) {
        d.assign(n, INF);
    }
};

int main()
{
    int n;
    cin >> n;
    Graph g(n);
    for (int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int v, c;
            cin >> v >> c;
            g.es.push_back({u, v, c});
        }
    }

    g.d[0] = 0;
    for (int i = 0; i < n - 1; i++) {
        for (edge e : g.es) {
            if (g.d[e.u] != INF && g.d[e.v] > g.d[e.u] + e.c) {
                g.d[e.v] = g.d[e.u] + e.c;
            }
        }
    }

    for (int i = 0; i < n; i++) {
        cout << i << " " << g.d[i] << endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
int e[111][111],d[111];
int used[111];
signed main(){
  int n;
  cin>>n;
  int INF=1LL<<55LL;
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      e[i][j]=INF;
  for(int i=0;i<n;i++){
    int u,k;
    cin>>u>>k;
    for(int j=0;j<k;j++){
      int v,c;
      cin>>v>>c;
      e[u][v]=min(e[u][v],c);
    }
  }
  memset(used,0,sizeof(used));
  for(int i=0;i<n;i++) d[i]=INF;
  d[0]=0;
  while(1){
    int u=-1;
    for(int i=0;i<n;i++){
      if(used[i]) continue;
      if(d[i]==INF) continue;
      if(u<0||d[i]<d[u]) u=i;
    }
    if(u<0) break;
    used[u]=1;
    for(int i=0;i<n;i++){
      d[i]=min(d[i],d[u]+e[u][i]);
    }
  }
  for(int i=0;i<n;i++) cout<<i<<" "<<d[i]<<endl;
  return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<algorithm>
#include<map>
#include<queue>
#include<iostream>
#include <iomanip>
#include<string>
#include<math.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int m, n, i, j, k, a, b, d;
int dis[1010][1010],e[1010], r[1010];
void init()
{
	memset(dis, inf, sizeof(dis));
	for (i = 0; i < 1010; i++)
		dis[i][i] = 0;
}
void add(int a, int b, int c)
{
	dis[a][b] = min(dis[a][b], c);
}
void floyd()
{
	for (k = 0; k < n; k++)
		for (i = 0; i < n; i++)
			for (j = 0; j < n; j++)
				if (dis[i][j] > dis[i][k] + dis[k][j])
					dis[i][j] = dis[i][k] + dis[k][j];
}
int main()
{
	int x, t, u, v;;
	scanf("%d", &n);
	init();
	for (i = 0; i < n; i++)
	{
		scanf("%d %d", &x, &t);
		for (j = 0; j < t; j++)
		{
			scanf("%d %d", &u, &v);
			add(i, u, v);
		}
	}
	floyd();
	for(i=0;i<n;i++)
		printf("%d %d\n",i, dis[0][i]);
	return 0;
}

C++: #include <iostream>
#include <queue>
#include <utility>
#include <vector>
#include <functional>
using namespace std;
int cost[100][100];
const int INF = 10000000;
int dijkstra(int n,int s,int g){
	typedef pair<int,int> P;
	priority_queue<P,vector<P>,greater<P> > pq;
	P p,tp;
	for(int i = 0;i < n;++i){
		p.first = cost[s][i];
		p.second = i;
		if(i == s) p.first = 0;
		pq.push(p);
	}
	while(!pq.empty()){
		p = pq.top();
		pq.pop();
		if(p.second == g) break;
		for(int i = 0;i < n;++i){
			if(cost[p.second][i] != INF){
				tp.first = p.first + cost[p.second][i];
				tp.second = i;
				pq.push(tp);
			}
		}
	}
	return p.first;
}
int main(){
	int n,m,a,b,c;
	cin >> n;
	for(int i = 0;i < 100;++i){
		for(int j = 0;j < 100;++j){
			cost[i][j] = INF;
		}
	}
	for(int i = 0;i < n;++i){
		cin >> a >> m;
		for(int j = 0;j < m;++j){
			cin >> b >> c;
			cost[a][b] = c;
		}
	}
	for(int i = 0;i < n;++i){
		cout << i << " " << dijkstra(n,0,i) << endl;
	}
	return 0;
}