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;

static const int MAX = 100;
static const int INFTY = (1 << 21);
static const int WHITE = 0, GRAY = 1, 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){
	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<string.h>
using namespace std;
#define WHITE 0
#define GLAY 1
#define BLACK 2
#define INFTY 1000000
int MAP[100][100],color[100],d[100];
int main()
{
	memset(MAP,INFTY,sizeof(MAP));
	int n,u,k,v,c;
	int minv;
	cin >> n ;
	for(int i = 0; i < n; i++){
		cin >> u >> k;
		for(int j = 0; j < k; j++){
			cin >> v >> c;
			MAP[u][v] = c;
		}
	}
	for(int i=0;i<n;i++){
		d[i] = INFTY;
		color[i] = WHITE;
	}
	d[0] = 0;
	color[0] = GLAY;
	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 && MAP[u][v] != INFTY){
				if(d[v] > d[u] + MAP[u][v]){	//d[v]:??????
					d[v] = d[u] + MAP[u][v];
				}
			}
		}
	}
	for(int i=0;i<n;i++){
		cout << i << " " << ( d[i]==INFTY ? -1 : d[i]) << endl;
	}
 	return 0;
}

C++: #include<iostream>
#include<vector>
#include<list>
#define INF 1e9
using namespace std;

void Dikstra(const vector<vector<pair<int, int> > >& G, vector<int>& d){
    d[0] = 0;
    list<int> i_gray;
    i_gray.push_back(0);
    vector<bool> is_black(d.size(), false);
    is_black[0] = true;
    while (!i_gray.empty()) {
        list<int>::iterator min_it = i_gray.begin();
        for (list<int>::iterator it = i_gray.begin(); it != i_gray.end(); it++) {
            if (d[*it] < d[*min_it]) min_it = it;
        }
        is_black[*min_it] = true;
        for (int i = 0; i < G[*min_it].size(); i++) {
            int v = G[*min_it][i].first;
            int w = G[*min_it][i].second;
            if (!is_black[v] && d[*min_it] + w < d[v]) {
                if (d[v] == INF) i_gray.push_back(v);
                d[v] = d[*min_it] + w;
            }
        }
        i_gray.erase(min_it);
    }
}

int main(){
    int n;
    cin >> n;
    vector<vector<pair<int, int> > > 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[u].push_back(make_pair(v, c));
        }
    }
    vector<int> d(n, INF);
    Dikstra(G, d);
    for (int i = 0; i < n; i++) {
        cout << i << " " << d[i] << endl;
    }

    return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <vector>
#include <tuple>
using namespace std;

#define NUM 100
#define NIL -1
#define INF 1000000000
#define WHITE 0
#define BLACK 1
int node_num;
vector<tuple<int, int>> G[NUM];
int V[NUM];
int color[NUM];

void init(void){
    scanf("%d", &node_num);

    for(int i = 0; i < node_num; i++){
        int u, k;
        scanf("%d", &u);
        scanf("%d", &k);

        for(int j = 0; j < k; j++){
            int v_, c;
            scanf("%d", &v_);
            scanf("%d", &c);
            G[u].push_back(make_tuple(v_, c));
        }
    }

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

void updateAround(int n){
    color[n] = BLACK;
    for(int i = 0; i < G[n].size(); i++){
        V[get<0>(G[n][i])] = min(V[get<0>(G[n][i])], V[n] + get<1>(G[n][i]));
    }

    int min_index = NIL;
    int min_value = INF;
    for(int i = 0; i < node_num; i++){
        if(color[i] == BLACK){
            continue;
        }
        if(V[i] < min_value){
            min_value = V[i];
            min_index = i;
        }
    }
    if(min_index != NIL){
        updateAround(min_index);
    }
}

int main(void){
    init();

    V[0] = 0;
    updateAround(0);

    for(int i = 0; i < node_num; i++){
        printf("%d %d\n", i, V[i]);
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
#define M 1000000007
int main(void)
{
	int n,i,j,u,k,v,c,min,ki;
	int ri[101][101],flg[101];
	int ans[101];
	scanf("%d",&n);
	for(i=0;i<=100;i++) for(j=0;j<=100;j++) ri[i][j]=M;
	for(i=0;i<n;i++){
		scanf("%d %d",&u,&k);
		for(j=0;j<k;j++){
			scanf("%d %d",&v,&c);
			if(ri[i][v]>c){
				ri[i][v]=c;
			}
		}
	}
	for(i=0;i<n;i++) flg[i]=0,ans[i]=M;
	//for(i=0;i<n;i++) for(j=0;j<n;j++) if(ri[i][j]!=M) printf("%d-%d %d\n",i,j,ri[i][j]);
	ans[0]=0;
	for(i=0;i<n;i++){
		min=M;
		for(j=0;j<n;j++){
			if(flg[j]==0&&ans[j]<min){
				min=ans[j];
				ki=j;
			}
		}
		flg[ki]=1;
		for(j=0;j<n;j++){
			if(min+ri[ki][j]<ans[j]){
				ans[j]=min+ri[ki][j];
			}
		}
	}
	//for(i=0;i<n;i++) printf("%d\n",ans[i]);
	for(i=0;i<n;i++) printf("%d %d\n",i,ans[i]);
	return 0;
}