Go: package main

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

type Item struct {
	value    int // The value of the item; arbitrary.
	priority int // The priority of the item in the queue.
	// The index is needed by update and is maintained by the heap.Interface methods.
	index int // The index of the item in the heap.
}
type PriorityQueue []*Item

func (pq PriorityQueue) Len() int { return len(pq) }
func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].priority < pq[j].priority
}
func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}
func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}
func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

type Q struct {
	pq *PriorityQueue
	ds map[int]int // It has always same value as pq. For random access.
}

func newQ() *Q {
	pq := new(PriorityQueue)
	heap.Init(pq)
	return &Q{
		pq: pq,
		ds: make(map[int]int),
	}
}
func (q *Q) pop() (u, d int) {
	item := heap.Pop(q.pq).(*Item)
	delete(q.ds, item.value)
	return item.value, item.priority
}
func (q *Q) get(u int) (int, bool) { // returns d
	d, ok := q.ds[u]
	return d, ok
}
func (q *Q) set(u, d int) {
	q.ds[u] = d
	for _, item := range *q.pq {
		if item.value != u {
			continue
		}

		item.priority = d
		heap.Fix(q.pq, item.index)
		return
	}
	heap.Push(q.pq, &Item{
		priority: d,
		value:    u,
	})
}
func (q *Q) len() int {
	return len(q.ds)
}

func main() {
	r := bufio.NewReader(os.Stdin)

	var n int
	fmt.Fscan(r, &n)
	cs := make([]map[int]int, n) // []v_i -> c_i
	for h := 0; h < n; h++ {
		var u, k int
		fmt.Fscan(r, &u, &k)
		m := make(map[int]int)
		for i := 0; i < k; i++ {
			var v, c int
			fmt.Fscan(r, &v, &c)
			m[v] = c
		}

		cs[u] = m
	}

	q := newQ()
	q.set(0, 0)
	visited := make(map[int]struct{})
	out := make([]int, n)

	for q.len() > 0 {
		u, d := q.pop()
		for uu, c := range cs[u] {
			// Consider the connection between u and uu.
			if _, ok := visited[uu]; ok {
				continue
			}
			dd := d + c
			if d, ok := q.get(uu); !ok || d > dd {
				q.set(uu, dd)
			}
		}

		out[u] = d
		visited[u] = struct{}{}
	}

	for u, d := range out {
		fmt.Println(u, d)
	}
}

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

C++: // Ref : https://book.mynavi.jp/ec/products/detail/id=35408

#include <iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1 << 21);
static const int WHITE = 0; // unsearched state
static const int GRAY = 1; // ungrouped state
static const int BLACK = 2; // grouped state

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

C++: #include <iostream>
using namespace std;
#include <vector>
#include <utility>
#include <algorithm>
using P = pair<int,int>;
#define rep(i,n) for(int i=0;i<n;i++)
vector<bool> seen;
int main(){
    int N,t;
    cin >> N;
    vector<int> costs(N);
    vector<vector<P>> T(N,vector<P>(N));
    vector<int> v(N);
    vector<int> ved(N);
    P pa;
    rep(i,N){
       cin >> t;
       cin >> v[i];
       rep(j,v[i]){
           cin >> T[i][j].second >> T[i][j].first;
       }
       sort(T[i].begin(),T[i].begin()+v[i]);
    }
    seen.assign(N, false);
    costs.assign(N,1e9);
    seen[0] = true;
    costs[0] = 0;
    rep(i,N-1){
        pa.first = 1e9;
        rep(j,N){
            rep(k,v[j]){
                if(seen[T[j][k].second])continue;
                if(pa.first > costs[j]+T[j][k].first){
                    pa.first = costs[j]+T[j][k].first;
                    pa.second = T[j][k].second;
                }
            }
        }
        seen[pa.second] = true;
        costs[pa.second] = pa.first;
    }
    rep(i,N){
        cout << i << " " << costs[i] << endl;
    }
    return 0;
}