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

	route := make([][]Node, n)
	weight := make([]int, n)
	for i := 0; i < n; i++ {
		weight[i] = NIL
	}

	for i := 0; i < n; i++ {
		u := scanInt()
		k := scanInt()
		route[i] = make([]Node, k)
		for j := 0; j < k; j++ {
			route[u][j] = Node{id: scanInt(), weight: scanInt()}
		}
	}

	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 _, nextNode := range route[node.id] {
			if weight[nextNode.id] != NIL {
				continue
			}
			nextNode.weight += node.weight
			heap.Push(h, nextNode)
		}
	}

	for i, w := range weight {
		fmt.Println(i, w)
	}
}

C++: #include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

static const int MAX_NUM = 10000;
enum eState {
    NO_VISIT = 0,
    NOW_VISIT,
    END_VISIT
};

void SSSP(vector<pair<int, int> > matrix[], int num)
{
    int i;
    int cost[MAX_NUM];
    eState state[MAX_NUM] = {NO_VISIT};
    priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > PQ;

    for (i = 0; i < num; i++) {
        cost[i] = 100000 * MAX_NUM;
    }

    PQ.push(make_pair(0, 0));
    cost[0]  = 0;
    state[0] = NOW_VISIT;

    while (PQ.empty() == false) {
        int tid;
        int nid, ncost;
        pair<int, int> target = PQ.top();
        PQ.pop();

        tid = target.second;
        state[tid] = END_VISIT;

#if 0
        if (cost[tid] < target.second) {
            continue;
        }
#endif

        for (i = 0; i < matrix[tid].size(); i++) {
            nid   = matrix[tid][i].second;
            ncost = matrix[tid][i].first;
            if ((state[nid] != END_VISIT) && (cost[nid] > (ncost + cost[tid]))) {
                cost[nid]  = ncost + cost[tid];
                state[nid] = NOW_VISIT;
                PQ.push(make_pair(cost[nid], nid));
            }
        }
    }

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

    return;
}

int main(void)
{
    int i, j;
    int num;
    int target, pathnum;
    int path, cost;
    vector<pair<int, int> > matrix[MAX_NUM];

    scanf("%d", &num);
    for (i = 0; i < num; i++) {
        scanf("%d %d", &target, &pathnum);
        for (j = 0; j < pathnum; j++) {
            scanf("%d %d", &path, &cost);
            matrix[target].push_back(make_pair(cost, path));
        }
    }

    SSSP(matrix, num);

    return 0;
}

C++: #include<map>
#include<list>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<cstring>
#include<iostream>
#include<functional>
#include<algorithm>
using namespace std;
#define LOOP1(n) for(int i=0;i<n;i++)
#define LOOP2(n) for(int j=0;j<n;j++)
#define LOOP3(n) for(int k=0;k<n;k++)
#define Psi pair<string,int>
#define Pis pair<int,string>
#define Pii pair<int,int>
// ??????????????????memset(a,0,sizeof(a));
// ?´???°?????? if(x<2)return0;else if(x==2)return1;if(x%2==0)return0;for(i=3;i*i<=x;i+=2){if(x%i==0)return0;}return1;}p440
//vector size();push_back(x);pop_back();begin();end();insert(p,x);erase(p);clear();
//stack  size();top();pop();push(x);emtpy();
//queue  size();front();pop();push(x);empty();
//priority_queue< ??? , ??\???????????? , less<???> or greater<???> > <int , vector<int> , greater<int> >
/*******************************************/
/* vector<int> v     vector<int> v[100]    */
/* ???[1]          ?????? [1,1][1,2][1,3]     */
/*   [2]               [2,1][2,2][3,3]     */
/*   [3]               [3,1][2,2][3,3]     */
/*******************************************/
static const int MAX = 10000;
static const int WHITE = 1;
static const int GRAY = 2;
static const int BLACK = 3;
static const int INFTY = (1 << 21);
int d[MAX]; int color[MAX]; 
int main(){
	vector<pair<int, int>> v[MAX];
	int n, k, uu;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> uu >> k;
		for (int j = 0; j < k; j++){
			Pii p;
			cin >> p.first >> p.second;
			v[i].push_back(p);
		}
	}
	for (int i = 0; i < n; i++){
		d[i] = INFTY;
		color[i] = WHITE;
	}
	d[0] = 0; int u = 0;
	while (1){
		int mincost = INFTY;
		LOOP1(n){
			if (color[i] != BLACK && mincost > d[i]){
				mincost = d[i];
				u = i;
			}
		}
		if (mincost == INFTY) break;
		color[u] = BLACK;
		for (int j = 0; j < v[u].size(); j++){
			if (color[v[u][j].first] != BLACK && d[u] + v[u][j].second < d[v[u][j].first]){
				color[v[u][j].first] = GRAY;
				d[v[u][j].first] = d[u] + v[u][j].second;
			}
		}
	}
	LOOP1(n){
		cout << i << ' ' << d[i] << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<list>
#define INF 2e9
using namespace std;

void Dikstra(const vector<vector<pair<int, int> > >& G, vector<int>& d){
    d[0] = 0;
    list<int> i_gray;
    i_gray.push_back(0);
    vector<bool> is_black(d.size(), false);
    is_black[0] = true;
    while (!i_gray.empty()) {
        list<int>::iterator min_it = i_gray.begin();
        for (list<int>::iterator it = i_gray.begin(); it != i_gray.end(); it++) {
            if (d[*it] < d[*min_it]) min_it = it;
        }
        is_black[*min_it] = true;
        for (int i = 0; i < G[*min_it].size(); i++) {
            int v = G[*min_it][i].first;
            int w = G[*min_it][i].second;
            if (!is_black[v] && d[*min_it] + w < d[v]) {
                if (d[v] == INF) i_gray.push_back(v);
                d[v] = d[*min_it] + w;
            }
        }
        i_gray.erase(min_it);
    }
}

int main(){
    int n;
    cin >> n;
    vector<vector<pair<int, int> > > G(n);
    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;
            G[u].push_back(make_pair(v, c));
        }
    }
    vector<int> d(n, INF);
    Dikstra(G, d);
    for (int i = 0; i < n; i++) {
        cout << i << " " << d[i] << endl;
    }

    return 0;
}