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 <bits/stdc++.h>
using namespace std;
#define INFTY (1<<30)

int n;
vector<int> color(101,0),d(101,INFTY),p(101);
vector<vector<int>> M(101,vector<int>(101,INFTY));

void dijkstra(int s){
    d[s]=0;
    p[s]=-1;
    while(1){
        int u;
        int mincost=INFTY;
        for(int i=0;i<n;i++){
            if(color[i]!=2&&d[i]<mincost){
                mincost=d[i];
                u=i;
            }
        }
        if(mincost==INFTY) break;
        color[u]=2;
        for(int v=0;v<n;v++){
            if(color[v]!=2&&M[u][v]!=INFTY){
                if(d[u]+M[u][v]<d[v]){
                    d[v]=d[u]+M[u][v];
                    p[v]=u;
                    color[v]=1;
                }
            }
        }
    }
}

int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        int a,b,c,k;
        cin>>a>>k;
        for(int j=0;j<k;j++){
            cin>>b>>c;
            M[a][b]=c;
        }
    }

    dijkstra(0);

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

C++: 
#include<bits/stdc++.h>

using namespace std;

const int maxn=1e2+5;
const int inf=(1<<21);
const int white=0;
const int gray=1;
const int black=2;

int n,m[maxn][maxn];

void dijkstra()
{
    int minv,d[maxn],book[maxn];
    for(int i=0;i<n;i++){
        d[i]=inf;
        book[i]=0;
    }
    d[0]=0;
    while(1){
        minv=inf;
        int u=-1;
        for(int i=0;i<n;i++){
            if(minv>d[i]&&book[i]==0){
                u=i;
                minv=d[i];
            }
        }
        if(u==-1){
            break;
        }
        book[u]=1;
        for(int v=0;v<n;v++){
            if(book[v]==0&&(d[v]>d[u]+m[u][v])){
                    d[v]=d[u]+m[u][v];
            }
        }
    }
    for(int i=0;i<n;i++){
        cout<<i<<" "<<(d[i]==inf?-1:d[i])<<endl;
    }
}

int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            m[i][j]=inf;
        }
    }
    int u,k,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;
}
/*
5
0 3 2 3 3 1 1 2
1 2 0 2 3 4
2 3 0 3 3 1 4 1
3 4 2 1 0 1 1 4 4 3
4 2 2 1 3 3 
*/

C++: #include <iostream>
using namespace std;
static const int Max = 100;
static const int Inf = 100000000; // ??????
static const int Nil = -1; // 

enum Status {
	Not_Searched = 0,
	Connected = 1,
	Searched = 2
};

int n;
int M[Max][Max] = {};
Status st[Max] = {}; 
int min_cost[Max] = {}; // min cost of point from start
//int parent[Max] = {}; // ??????index

void dijkstra() {
	for (int i = 0; i < n; i++) {
		min_cost[i] = Inf;
	}

	min_cost[0] = 0;
	st[0] = Connected;
	while (1) {
		int mincost = Inf;
		int min_index = Nil;
		for (int i = 0; i < n; i++) {
			if (st[i] != Searched && mincost > min_cost[i]) {
				mincost = min_cost[i];
				min_index = i;
			}
		}
		if (min_index == Nil) break;
		// index ?????????????????????????????????
		st[min_index] = Searched;
		for (int i = 0; i < n; i++) {
			// min_index ??¨???????????£??????????????????????????????????????????
			if (st[i] != Searched && M[min_index][i] != Inf) {
				if (min_cost[i] > min_cost[min_index] + M[min_index][i]) {
					min_cost[i] = min_cost[min_index] + M[min_index][i];
					st[i] = Connected;
				}
			}
		}
	}
	for (int i = 0; i < n; i++) {
		cout << i << " " << (min_cost[i] == Inf ? -1 : min_cost[i]) << endl;
	}
	return;
}

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

C++: #include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<stack>
#include<queue>
#include<sstream>
#include<string>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i);

using namespace std;

struct node{
	int pos;
	int prev;
	double cost;

	node(int t_pos,int t_prev,double t_cost){
		pos = t_pos; prev = t_prev; cost = t_cost;
	}

	bool operator<(const node& a) const { //キューの中身を逆転
		return cost > a.cost;
	}
};

struct root{
	int to;
	double cost;

	root(int t_to,double t_cost){
		to = t_to; cost = t_cost;
	}

};

vector< vector <root> > roots;
int n,m,s,g;

double dp[101][101];

const double INF = 9e9;

void search(){

	fill_n((double *)dp,sizeof(dp)/sizeof(double),INF); //初期化	
	
	priority_queue<node> pq;

	rep(i,roots[s].size()){
	
		root r = roots[s][i];
		
		pq.push( node(r.to,s,r.cost) );
		dp[r.to][s] = r.cost;
	}

	while(!pq.empty()){

		node tn = pq.top();
		pq.pop();

		if( dp[tn.pos][tn.prev] != tn.cost) continue;

		if( tn.pos == g){
			cout << g << " " <<tn.cost << endl;
			return;
		}	

		rep(i,roots[tn.pos].size()){
			root r = roots[tn.pos][i];
			if(r.to == tn.prev) continue;

			for( int j = -1; j< 2; j++){
		//		if( tn.speed + j > 0 && tn.speed +j <= r.speed){
					double cost = tn.cost + r.cost;///(tn.speed+j);
					if( dp[r.to][tn.pos] > cost){
						dp[r.to][tn.pos] = cost;
						pq.push( node( r.to,tn.pos,cost));
					}
				//}
			}
		}
	}

	cout << "unreachable" << endl;
}


int main(){

		cin >> n;

		roots = vector< vector<root> >(n);

    rep(i,n){
      int num,m;
      cin >> num >> m;
      roots[num].push_back( root(num,0));
      rep(j,m){
        int r,cost;
        cin >> r>> cost;
        roots[num].push_back( root(r,cost));
      }
    }
    s=0;
    rep(i,n){
		  g=i;
      search();
    }
}