Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
type Node struct {
	cost int
	done bool
}

type Edge struct {
	to, cost int
}

const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	nodes := make([]Node, N)
	for i := 0; i < N; i++ {
		nodes[i].cost = INF
	}
	E := make([][]Edge, N)
	for i := 0; i < N; i++ {
		id, k := sc.nextInt(), sc.nextInt()
		for j := 0; j < k; j++ {
			to, cost := sc.nextInt(), sc.nextInt()
			E[id] = append(E[id], Edge{to, cost})
		}
	}
	nodes[0].cost = 0
	for {
		cur := 0
		minCost := INF
		for i := 0; i < N; i++ {
			n := nodes[i]
			if !n.done && n.cost < minCost {
				cur = i
				minCost = n.cost
			}
		}
		if minCost == INF {
			break
		}
		nodes[cur].done = true
		for i := 0; i < len(E[cur]); i++ {
			to, cost := E[cur][i].to, E[cur][i].cost+nodes[cur].cost
			if !nodes[to].done && cost < nodes[to].cost {
				nodes[to].cost = cost
			}
		}
	}

	for i := 0; i < N; i++ {
		fmt.Fprintln(wtr, i, nodes[i].cost)
	}
	wtr.Flush()
}

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