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>
using namespace std;
int n;
static const int MAX = 100;
static const int INF = (1 << 21);
int M[MAX][MAX];
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;


void dijkstra(){
    int minv;
    int d[MAX], color[MAX];

    for (int i = 0; i < n; i++){
        d[i] = INF;
        color[i] = WHITE;
    }

    d[0] = 0;
    // color[]

    while(1){
        minv = INF;
        int 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 i = 0; i < n; i++){
            if (color[i] != BLACK && d[i] > M[u][i] != INF){
                if (d[i] > d[u] + M[u][i]){
                    color[i] = GRAY;
                    d[i] = d[u] + M[u][i];
                }
            }
        }
    }
    for (int i = 0; i < n; i++){
            cout << i << " ";
            if (d[i] == INF){
                cout << -1 << endl;
            }else{
                cout << d[i] << endl;
            }
            
        }
}

int main(void){
    int tmp;

    cin >> n;

    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            M[i][j] = INF;
        }
    }

    int u, k;
    int v, c;
    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>

using namespace std;

int d[100];

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

    int graph[n][n];

    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            graph[i][j] = -1;

    for (int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int c, v;
            cin >> v >> c;
            graph[u][v] = c;
        }
    }

    for (int i = 0; i < n; i++)
        d[i] = 100000000;
    d[0] = 0;

    vector<int> queue;
    for (int i = 0; i < n; i++)
        queue.push_back(i);

    while (!queue.empty()) {
        int u = queue[0];
        size_t j = 0;
        for (size_t i = 0; i < queue.size(); i++)
            if (d[queue[i]] < d[u]) {
                u = queue[i];
                j = i;
            }
        queue.erase(queue.begin() + j);

        for (int v = 0; v < n; v++)
            if (graph[u][v] > 0)
                if (d[v] > d[u] + graph[u][v])
                    d[v] = d[u] + graph[u][v];
    }

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

    
    return 0;
}

C++: #include<stdio.h>
#include<limits.h>
#define NIL -1
static const int MAX = 1005;
static const int INFTY = (1<<21);

main(){
  int n, i, j, v, c, u, k, minV;
  int M[MAX][MAX], A[MAX], key[MAX], p[MAX];
  /*your code*/

  scanf("%d", &n);
  for ( i = 0; i< n; i++ ){
    for ( j = 0; j < n; j++ ){
      M[i][j] = INFTY;
    }
  }

  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &u, &k);
    for ( j = 0; j < k; j++ ){
      scanf("%d %d", &v, &c);
      M[u][v] = c;
    }
  }

  /*your code*/
  for(i = 0; i < n; i++){
    key[i] = INT_MAX;
    p[i] = NIL;
    A[i] = NIL;
  }
  
  key[0]=0;
  
  while(1){
    
    u = NIL;
    
    minV = INT_MAX;
    
    for(i = 0;  i < n; i++){
      
      if(key[i] < minV && A[i] == NIL){
	
	u = i;
	
	minV = key[i];
	
      }
      
    }  
    if(u == NIL)break;
    
    A[u] = u; 
    
    for(v = 0; v < n; v++){
      if((M[u][v]+key[u]) < key[v] && A[v] == NIL){
	key[v] = (M[u][v]+key[u]);
	p[v] = u;
      }
    }
  }
  
  for ( i = 0; i < n; i++ ){
    printf("%d %d\n", i, (key[i]==INFTY?-1:key[i]));
  }

  return 0;

}

C++: #include <iostream>
using namespace std;
#define MAX 100
#define INFTY (1<<30)
#define rep(i,n) for(int i=0;i<n;i++)
enum{
	white,
	gray,
	black,
};

int n,m[MAX][MAX];

 void dijkstra(){
 	int minv;
 	int d[MAX],color[MAX];
 	rep(i,n){
 		d[i]=INFTY;
 		color[i]=white;
 	}
	d[0]=0;
 	color[0]=gray;
 	while(1){
 		minv=INFTY;
 		int u=-1;
 		rep(i,n){
 			if(minv>d[i]&&color[i]!=black){
 				u=i;
 				minv=d[i];
 			}
 		}
 		if(u==-1)	break;
 		color[u]=black;
 		rep(v,n){
 			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;
 				}
 			}
 		}
 	}
 	rep(i,n){
 		cout<<i<<" ";
 		if(d[i]==INFTY)	cout<<-1<<endl;
 		else	cout<<d[i]<<endl;
 	}
 }

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

C++: #include<bits/stdc++.h>
using namespace std;
#define M 1000000007
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
typedef pair<int,int> P;
typedef pair<P,P> PP;

int main(void)
{
	int i,j,k,u,n,flg[10001],v,c,sum,ky[10001],t,min,g;
	PP ke[10001];
	scanf("%d",&n);
	sum=0;
	for(i=0;i<n;i++) ky[i]=M,flg[i]=0;
	ky[0]=0;
	for(i=0;i<n;i++){
		scanf("%d%d",&u,&k);
		for(j=sum;j<k+sum;j++){
			scanf("%d%d",&v,&c);
			ke[j].ff=u , ke[j].fs=v , ke[j].sf=c;
		}
		sum+=k;
	}
	sort(ke,ke+sum);
	//for(i=0;i<sum;i++) printf("ke[%d].ff=%d ke[%d].fs=%d ke[%d].sf=%d\n",i,ke[i].ff,i,ke[i].fs,i,ke[i].sf);
	for(i=0;i<sum;i++){
		/*min=M;
		for(j=0;j<sum;j++) if(flg[j]==0&&min>ky[j]) g=j,min=j;
		flg[g]=1;
		if(min==M) break;*/
		for(j=0;j<sum;j++){
			t=ky[ke[j].ff]+ke[j].sf;
			if(ky[ke[j].fs]>t) ky[ke[j].fs]=t;
		}
	}
	for(i=0;i<n;i++) printf("%d %d\n",i,ky[i]);
	return 0;
}