Go: package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

const NIL = -1

type Node struct {
	id     int
	weight int
}

func init() {
	sc.Split(bufio.ScanWords)
}

type NodeHeap []Node

func (h NodeHeap) Len() int           { return len(h) }
func (h NodeHeap) Less(i, j int) bool { return h[i].weight < h[j].weight }
func (h NodeHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *NodeHeap) Push(x interface{}) {
	*h = append(*h, x.(Node))
}

func (h *NodeHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()

	list := make([][]int, n)
	weight := make([]int, n)
	for i := range list {
		list[i] = make([]int, n)
		weight[i] = NIL
		for j := range list[i] {
			list[i][j] = NIL
		}
	}

	for i := 0; i < n; i++ {
		u := scanInt()
		k := scanInt()
		for j := 0; j < k; j++ {
			v := scanInt()
			w := scanInt()
			list[u][v] = w
		}
	}

	start := Node{id: 0, weight: 0}
	h := &NodeHeap{start}
	heap.Init(h)

	for h.Len() > 0 {
		node := heap.Pop(h).(Node)
		if weight[node.id] != NIL {
			continue
		}
		weight[node.id] = node.weight

		for i, w := range list[node.id] {
			if w == NIL {
				continue
			}
			heap.Push(h, Node{id: i, weight: w + node.weight})
		}
	}

	w := bufio.NewWriter(os.Stdout)
	for i := 0; i < n; i++ {
		fmt.Fprint(w, i)
		fmt.Fprint(w, " ")
		fmt.Fprint(w, weight[i])
		fmt.Fprintln(w)
	}
	w.Flush()
}

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();
    }
}