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