Go: package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)

	g := makeGraph(n)
	for i := 0; i < n; i++ {
		u := getNextInt(scanner)
		k := getNextInt(scanner)
		for ii := 0; ii < k; ii++ {
			v := getNextInt(scanner)
			c := getNextInt(scanner)
			g[u][v] = c
		}
	}

	ans := make([]int, n)
	im := make(IntMap, 1)
	im.increment(0)
	for len(im) < n {
		min := 1 << 30
		x := -1
		for u := range im {
			for v := 0; v < n; v++ {
				if im.get(v) != 0 {
					continue
				}
				if min > ans[u]+g[u][v] {
					min = ans[u] + g[u][v]
					x = v
				}
			}
		}
		im.increment(x)
		ans[x] = min
	}

	for i := 0; i < n; i++ {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d", i, ans[i]))
	}
	writer.Flush()
}

func makeGraph(n int) [][]int {
	g := make([][]int, n)
	for i := 0; i < n; i++ {
		g[i] = make([]int, n)
		for ii := 0; ii < n; ii++ {
			g[i][ii] = 1 << 30
		}
	}

	return g
}

// IntMap ...
type IntMap map[int]int

func (m IntMap) get(key int) int {
	if _, ok := m[key]; ok {
		return m[key]
	}
	return 0
}
func (m IntMap) increment(key int) {
	if _, ok := m[key]; ok == false {
		m[key] = 0
	}
	m[key]++
}

C++: #include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<sstream>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
////////////////////////////////////////////////////////////
const int MAX_V = 100;
typedef struct edge_{int to,cost;}edge;
typedef pair<int,int> P; 	//firstは最短経路,secondは頂点番号
int V; 										//頂点数
vector<vector<edge>> G(MAX_V);
int dp[MAX_V];

void dijkstra( int s ){
	//最短経路の値の小さいものから取り出せる
	priority_queue<P,vector<P>,greater<P>> que;
	for(int i = 0 ; i < V ; i++ ) dp[i] = INF;
	dp[s] = 0;
	que.push(pair<int,int>(0,s));
	while(!que.empty()){
		P p = que.top();
		que.pop();
		int v = p.second;
		if( dp[v] > p.first ) continue;
		for(int i = 0 ; i < G[v].size() ; i++ ){
			edge e = G[v][i];
			//cout << "here:" << i << " to:" << e.to << " cost:" << e.cost << endl;
			if( dp[e.to] > dp[v] + e.cost ){
				dp[e.to] = dp[v] + e.cost;
				que.push(pair<int,int>(dp[e.to],e.to));
			}
		}
	}
	return;
}
int main(){
	cin >> V;
		
	rep(i,0,V){
		int u,k;
		cin >> u >> k;
		rep(j,0,k){
			int v,c;
			cin >> v >> c;
			G[i].push_back(edge{v,c});
		}
	}
	
	dijkstra(0);

	rep(i,0,V){
		cout << i << " " << dp[i];
		if( i < V - 1 )
			cout << endl;
	}
	cout << endl;

	ret 0;
}

C++: #include <cstdio>
#include <iostream>
using namespace std;
#define INF 0xfffffff
int dis[10005][10005];
int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
            {
                if(i==j) 
				dis[i][j]=0;
                else dis[i][j]=INF;
            }
		for(int i=0;i<n;i++)
		{
			int a,b,c;
			scanf("%d",&a);
			int t;
			scanf("%d",&t);
			for(int j=0;j<t;j++)
			{
				scanf("%d %d",&b,&c);
				dis[a][b]=dis[b][a]=min(c,dis[a][b]);
			}
		}
		for(int k = 0; k < n; k++)  //枚举中间点（必须放最外层）
		  for(int i = 0; i < n; i++)  //枚举端点i
		    if(i != k)
		      for(int j = 0; j < n; j++)  //枚举端点j
		        if(i != j && j != k && dis[i][j] > dis[i][k] + dis[k][j])
		          dis[i][j] = dis[i][k] + dis[k][j];
		int f,g;
		f=0;g=0;
		dis[0][0]=0;
		for(g=0;g<n;g++)
		{
			printf ("%d %d\n",g,dis[f][g]);
		}
	}
}

C++: #include <iostream>
using namespace std;

static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n,M[MAX][MAX];

void dijkstra(){
    int minv;
    int d[MAX],color[MAX];
    
    for(int i=0; i<n; i++){
        d[i] = INFTY;
        color[i] = WHITE;
    }
    
    d[0] = 0;
    color[0] = GRAY;
    while(1){
        minv = INFTY;
        int u=-1;
        for(int i=0; i<n; i++){
            if(minv>d[i] && color[i] != BLACK){
                u = i;
                minv = d[i];
            }
        }
        if(u==-1) break;
        color[u] = BLACK;
        for(int v=0; v<n; v++){
            if(color[v] != BLACK && M[u][v] != INFTY){
                d[v] = d[u]+M[u][v];
                color[v] = GRAY;
            }
        }
    }
    for(int i=0; i<n; i++){
            cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
    }
}

int main(){
    cin >> n;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            M[i][j] = INFTY;
        }
    }
    
    int k,c,u,v;
    for(int i=0; i<n; i++){
        cin >> u >> k;
        for(int j=0; j<k; j++){
            cin >> v >> c;
            M[u][v] = c;
        }
    }
    
    dijkstra();
    
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#define MAX_V 100
#define INF 1e9
using namespace std;
int cost[MAX_V][MAX_V];
int d[MAX_V];
bool used[MAX_V];
int V;
void dijkstra(int s) {
	for (int i = 0; i < V; i++) {
		d[i] = INF;
		used[i] = false;
	}
	d[s] = 0;
	while (true) {
		int v = -1;
		for (int u = 0; u < V; u++) {
			if (!used[u] && ((v == -1) || d[u] < d[v])) {
				v = u;
			}
		}
		//全ての頂点が到達済み
		if (v == -1) {
			break;
		}
		//集合に新たに頂点を追加
		used[v] = true;
		for (int u = 0; u < V; u++) {
			d[u] = min(d[u], d[v] + cost[v][u]);
		}
	}
}

int main() {
	for (int i = 0; i < V+60; i++) {
		for (int j = 0; j < V+60; j++) {
			cost[i][j] = INF;//iからjへの辺の重さ
		}
	}
	cin >> V;
	for (int i = 0; i < V; i++) {
		int u;
		cin >> u;
		int k;
		cin >> k;
		for (int j = 0; j < k; j++) {
			int v;
			cin >> v;
			int c;
			cin >> c;
			cost[u][v] = c;
		}
	}
	dijkstra(0);

	for (int i = 0; i < V; i++) {
		cout << i << " " << d[i] << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#define INF 200001 
using namespace std;
  
int main(){
 int u,k,C,V,A[1000][1000],D[1000][1000],n;
  scanf("%d",&n);
   for(int i=0;i<n;i++)for(int j=0;j<n;j++)D[i][j] = INF;
   
  for(int i=0;i<n;i++){
      scanf("%d %d",&u,&k);    
      for(int j=0;j<k;j++){
    scanf("%d %d",&V,&C);
    D[u][V] = C;
      }    
  }
  for(int i=0;i<n;i++)D[i][i] = 0;
 
  for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++)D[i][j]= min(D[i][j],D[i][k] + D[k][j]);
 
  for(int i=0;i<n;i++)printf("%d %d\n",i,D[0][i]);
  
  return 0;
}