Go: package main

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

const (
	white int = iota
	gray
	black
)

type node struct {
	id     int
	parent int
	edge   []int
	weight []int
	color  int
}

type graph struct {
	nodes    []node
	distance []int
}

var infty = 1 << 32
var null = -1

func constructgraph() *graph {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)

	g := &graph{make([]node, n), make([]int, n)}

	for i := 0; i < n; i++ {
		id := nextInt(sc)
		edges := nextInt(sc)
		n := node{}
		n.id = id
		n.edge = make([]int, edges)
		n.weight = make([]int, edges)
		n.color = white
		for j := 0; j < edges; j++ {
			to := nextInt(sc)
			w := nextInt(sc)
			n.edge[j] = to
			n.weight[j] = w
		}
		g.nodes[id] = n
	}
	return g
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func (g *graph) preparedijkstra(s int) {
	for i := 0; i < len(g.nodes); i++ {
		g.nodes[i].color = white
		g.nodes[i].parent = null
		g.distance[i] = infty
	}
	g.distance[s] = 0
}

func (g *graph) dijkstra(s int) []int {
	g.preparedijkstra(s)

	for {
		var u int
		mincost := infty
		for i, d := range g.distance {
			if g.nodes[i].color != black && mincost > d {
				mincost = d
				u = i
			}
		}

		if mincost == infty {
			break
		}

		g.nodes[u].color = black

		for i, e := range g.nodes[u].edge {
			if g.nodes[e].color != black {
				if g.distance[e] > g.distance[u]+g.nodes[u].weight[i] {
					g.distance[e] = g.distance[u] + g.nodes[u].weight[i]
					g.nodes[e].parent = u
					g.nodes[e].color = gray
				}
			}
		}
	}
	return g.distance
}

func printShortestPath(d []int) {
	for i, v := range d {
		fmt.Printf("%d %d\n", i, v)
	}
}

func main() {
	g := constructgraph()
	d := g.dijkstra(0)
	printShortestPath(d)
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>

using namespace std;

// ---------------------
// repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

// ---------------------
#define INF (1 << 21)
typedef long long ll;

int main() {
  int n;
  cin >> n;

  vector<int> V[n];
  int E[n][n];
  int d[n];
  int visited[n];

  REP(x, n) {
    REP(y, n) {
      E[x][y] = INF;
    }
    d[x] = INF;
    visited[x] = 0;
  }

  REP(_, n) {
    int u, k;
    cin >> u >> k;
    REP(__, k) {
      int v, c;
      cin >> v >> c;
      V[u].push_back(v);
      E[u][v] = c;
      // E[v][u] = c;
    }
  }

  d[0] = 0;
  REP(_, n) {
    int minv = -1;
    int mincost = INF;
    REP(v, n) {
      if (!visited[v] && d[v] < mincost) {
        minv = v;
        mincost = d[v];
      }
    }
    visited[minv] = 1;
    for (vector<int>::iterator it = V[minv].begin(); it != V[minv].end(); it++) {
      if (E[minv][*it] < INF && d[minv] + E[minv][*it] < d[*it]) {
        d[*it] = d[minv] + E[minv][*it];
      }
    }
  }

  REP(i, n) {
    cout << i << " " << d[i] << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int INF=(int)1e9;

int main(){
    //入力パート
    int n; cin>>n;
    vector<pair<int,int>> tonari[110]; //隣接リスト 一つ目が行先の頂点で二つ目が辺のコスト
    vector<int> dist(n,INF); //各頂点の（暫定）最短距離を格納
    vector<bool> det(n,false); //各頂点の最短距離が確定しているか格納
    for(int i=0;i<n;++i){
        int u,k,c,v;
        cin>>u>>k;
        for(int j=0;j<k;++j){
            cin>>c>>v;
            tonari[u].push_back(make_pair(c,v));
        }
    }
    //探索パート
    dist[0]=0; //出発地点の最短距離は0
    for(int i=0;i<n;++i){
        int mini=INF,mini_node=-1; //未確定点の最短距離とその頂点番号を格納
        for(int j=0;j<n;++j){ //最短距離が最小の点を探索
            if(det[j]) continue; //確定している点は対象外
            if(dist[j]<mini){
              mini=dist[j];
              mini_node=j;
            }
        }
        det[mini_node]=true; //最短距離を確定させる
        for(pair<int,int> tsugi:tonari[mini_node]){
            dist[tsugi.first]=min(dist[tsugi.first],dist[mini_node]+tsugi.second); //隣接ノードの値の更新
        }
    }
    
    //出力パート
    for(int i=0;i<n;++i){
        cout<<i<<" "<<dist[i]<<endl;
    }
    return 0; 
}

C++: #include <iostream>
using namespace std;
 
#define MAX   100
#define INFTY (1 << 21)
#define WHITE 0
#define GRAY  1
#define BLACK 2
 
int n, M[MAX][MAX];
 
void dijkstra() {
  int d[MAX], p[MAX], color[MAX];
  int minv, u;
  for ( int i = 0; i < n; i++ ) {
    d[i] = INFTY;
    p[i] = -1;
    color[i] = WHITE;
  }
 
  d[0] = 0;
color[0] = GRAY;
  while ( 1 ) {
    minv = INFTY;
    u = -1;
    for ( int i = 0; i < n; i++ ) {
      if ( minv > d[i] && color[i] != BLACK ) {
        minv = d[i];
u = i;
      }
    }
    if ( u == -1 ) break;
    color[u] = BLACK;
    for ( int v = 0; v < n; v++ ) {
      if ( color[v] != BLACK && M[u][v] != INFTY ) {
        if ( d[v] > d[u] + M[u][v] ) {
          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<cstdio>
#include<cstring>
#define INF 200001 
using namespace std;
int n;
int A[1000][1000];
int d[1000];
bool used[1000];
int D[1000][1000];
 
void Init(int f){
  for(int i=0;i<f;i++){
    for(int j=0;j<f;j++)D[i][j] = INF;
  }
 
}
 
int main(){
  scanf("%d",&n);
  int u,k,C,V;
  Init(n);
  
  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;
    D[V][u] = 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;
}

C++: #include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>

using namespace std;

#define MAX_N 100
#define INF 100

int cost[MAX_N][MAX_N];
int d[MAX_N];
bool used[MAX_N];
int V;

void dijkstra(int s) {
	fill_n(d, V, INF);
	fill_n(used, V, false);
	d[s] = 0;

	while (1) {
		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() {
	int n;
	cin >> n;
	V = n;
	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		fill_n(cost[u], n, INF);
		for (int j = 0; j < k; j++) {
			int v, c;
			cin >> v >> c;
			cost[u][v] = c;
		}
	}
	dijkstra(0);
	for (int i = 0; i < n; i++) {
		cout << i << " " << d[i] << endl;
	}
	
	return 0;
}