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 <iostream>
#include <vector>
using namespace std;

int main() {
    int n;
    cin >> n;

    int a[n][n];
    int done[n]; // -1: まだ ソレ以外: 確定距離
    for (int i = 0; i < n; ++i) {
        done[i] = -1;
        for (int j = 0; j < n; ++j) {
            a[i][j] = -1;
        }
    }
    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;
            a[i][v] = c;
        }
    }

    // デバッグ用
//     for (int i = 0; i < n; ++i) {
//         for (int j = 0; j < n; ++j) {
//             cout << i << " " << j << " " << a[i][j] << endl;
//         }
//     }

    // 最初は0が確定済みのノードとなる
    done[0] = 0;

    // 確定済みのノードから行ける、未到達の最小のノードを探す
    // その最小のノードは次の確定済みとする...
    // とりあえずデバッグがてら10回す (最終的にwhileにして条件で対応する)
    // 全てdoneになったら終了
    for (int r = 0; r < n-1; ++r) {
        int next_node = -1;
        int next_cost = 1000000;
        for (int i = 0; i < n; ++i) {
            if (done[i] == -1) {
                // 未確定であれば何もしない
                continue;
            }

            for (int j = 0; j < n; ++j) {
                // 到達済みは見ない
                if (done[j] != -1) {
                    continue;
                }

                // コストが-1なら到達できない
                if (a[i][j] == -1) {
                    continue;
                }

                // 行けるところのコスト (iまでの距離+そこからの距離) を探す
//                cout << "src:" << i << " dst:" << j << " cost:" << a[i][j] << " total:" << done[i] + a[i][j] << endl;

                // 今のnext_costよりもtotalcostが小さければ、次のノードにしたい
                if ((done[i] + a[i][j]) < next_cost) {
                    next_cost = done[i] + a[i][j];
                    next_node = j;
                }
            }
        }
//        cout << "iter:" << r << endl;
//        cout << "next_node:" << next_node << endl;
//        cout << "next_cost:" << next_cost << endl;
        done[next_node] = next_cost;
    }

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

    return 0;
}

C++: #include<stdio.h>
#define MAX 100
#define INFTY (2<<21)
#define WHITE 0
#define GRAY 1
#define BLACK 2

int M[MAX][MAX];
int d[MAX];
int color[MAX];

void dijkstra(int n) {
    int u, mincost;
    d[0] = 0;
    color[0] = GRAY;

    while (true) {
        mincost = INFTY;
        u = -1;

        for (int i=0; i<n; i++) {
            if (color[i]!=BLACK && d[i]<mincost) {
                u = i;
                mincost = d[i];
            }
        }

        if (u==-1) break;
        color[u] = BLACK;

        for (int i=0; i<n; i++) {
            if (color[i]!=BLACK && M[u][i]<INFTY) {
                color[i] = GRAY;
                if (d[u]+M[u][i]<d[i]) {
                    d[i] = d[u] + M[u][i];
                }
            }
        }
    }
}

int main() {
    int n, k, v, c, u;
    scanf("%d", &n);

    for (int i=0; i<n; i++) {
        d[i] = INFTY;
        color[i] = WHITE;
        for (int j=0; j<n; j++) {
            M[i][j] = INFTY;
        }
    }

    for (int i=0; i<n; i++) {
        scanf("%d %d", &u, &k);
        for (int j=0; j<k; j++) {
            scanf("%d %d", &v, &c);
            M[u][v] = c;
        }
    }

    dijkstra(n);

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

    return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int map[100][100];
int n;
int d[100];
int color[100];
int INF = 1000000;
void solve() {
	int all = 1;
	d[0] = 0;
	color[0] = 1;
	vector<int>v;
	v.push_back(0);
	while (all != n)
	{
		int min = INF;
		int k;
		for (int i = 0; i < v.size(); i++) {
			for (int j = 0; j < n; j++) {
				if (!color[j] && d[v[i]] + map[v[i]][j] <= d[j]) {
					d[j] = d[v[i]] + map[v[i]][j];
					if (d[j] < min) {
						min = d[j];
						k = j;
					}
				}
			}
		}
		color[k] = 1;
		v.push_back(k);
		all++;
	}
}
int main(void) {
	cin >> n;
	for (int i = 0; i < n; i++) {
		d[i] = INF;
		for (int j = 0; j < n; j++) map[i][j] = INF;
	}
	for (int i = 0; i < n; i++) {
		int k,all;
		cin >> k>>all;
		for (int j = 0; j < all; j++) {
			int a, b;
			cin >> a >> b;
			map[k][a] = b;
		}
	}
	solve();
	for (int i = 0; i < n; i++) {
		cout << i<<" "<<d[i]<<endl;
	}
}

C++: //
// Created by tattsun on 2017/02/16.
//

#include <iostream>

#define MAX_N 101
#define NIL -1
#define INFTY 1000000
#define TOTAL_INFTY INFTY*MAX_N

using namespace std;

enum Status {
    White,
    Gray,
    Black,
};

int n;
int w[MAX_N][MAX_N];
int d[MAX_N], parent[MAX_N];
Status st[MAX_N];

int min(int x, int y) {
    if(x < y) return x;
    return y;
}

void dijkstra() {
    for(int i=0; i<n; i++) {
        d[i] = TOTAL_INFTY;
        st[i] = White;
        parent[i] = NIL;
    }

    int p = 0;
    d[p] = 0;

    while(true) {
        if(p == -1) break;
        st[p] = Black;

        for(int i=0; i<n; i++) {
            if(w[p][i] != TOTAL_INFTY && st[i] != Black) {
                d[i] = min(d[i], d[p] + w[p][i]);
                st[i] = Gray;
            }
        }

        p = -1;
        int c = TOTAL_INFTY;
        for(int i=0; i<n; i++) {
            if(st[i] == Gray && d[i] < c) {
                p = i;
                c = d[i];
            }
        }
    }
}

int main() {
    for(int i=0; i<MAX_N; i++) {
        for (int j = 0; j < MAX_N; j++) {
            w[i][j] = TOTAL_INFTY;
        }
    }

    cin >> n;

    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;
            w[u][v] = c;
        }
    }

    dijkstra();

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