Go: package main

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

type Node struct {
	Id int
	Dis int
}

type PriorityQueue []*Node

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].Dis < pq[j].Dis
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *PriorityQueue) Push(x interface{}) {
	*pq = append(*pq, x.(*Node))
}

func (pq *PriorityQueue) Pop() interface{} {
	n := len(*pq)
	pop := (*pq)[n-1]
	*pq = (*pq)[0:n-1]
	return pop
}

func main() {
	var n int
	fmt.Scan(&n)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	g := make([][]int, n)
	c := make([][]int, n)
	pq := make(PriorityQueue, 0, n)
	d := make([]int, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		u, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())
		g[u] = make([]int, k)
		c[u] = make([]int, k)
		for j := 0; j < k; j++ {
			sc.Scan()
			g[u][j], _ = strconv.Atoi(sc.Text())
			sc.Scan()
			c[u][j], _ = strconv.Atoi(sc.Text())
		}

		if u == 0 {
			d[u] = 0
		} else {
			d[u] = 1 << 30
		}
		pq.Push(&Node{u, d[u]})
	}
	heap.Init(&pq)

	for pq.Len() > 0 {
		node := heap.Pop(&pq).(*Node)
		for i := 0; i < len(g[node.Id]); i++ {
			nextId := g[node.Id][i]
			nextDis := node.Dis + c[node.Id][i]
			if nextDis < d[nextId] {
				d[nextId] = nextDis
				heap.Push(&pq, &Node{nextId, nextDis})
			}
		}
	}

	wr := bufio.NewWriter(os.Stdout)
	for i := 0; i < n; i++ {
		wr.WriteString(strconv.Itoa(i))
		wr.WriteString(" ")
		wr.WriteString(strconv.Itoa(d[i]))
		wr.WriteString("\n")
	}
	wr.Flush()
}

C++: #include <stdio.h>
#include <iostream>
#include <queue>
using namespace std;

#define NIL -1
#define INF 100000000
#define WHITE 1
#define GREY 2
#define BLACK 3
#define N_MAX 100

int G[N_MAX][N_MAX];
int V[N_MAX];
int V_value[N_MAX];

void init(){
    for(int i = 0; i < N_MAX; i++){
        V[i] = WHITE;
        V_value[i] = INF;
    }

    for(int i = 0; i < N_MAX; i++){
        for(int j = 0; j < N_MAX; j++){
            G[i][j] = NIL;
        }
    }
}

int main(void){
    init();
    int n;
    scanf("%d\n", &n);

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

    priority_queue<pair<int, int>> PQ;

    V[0] = BLACK;
    V_value[0] = 0;
    int new_node = 0;
    
    while(1){
        //printf("new_node: %d\n", new_node);
        for(int i = 0; i < n; i++){
            if(G[new_node][i] != NIL && V[i] == WHITE){
                V_value[i] = min(V_value[i], V_value[new_node] + G[new_node][i]);
                //printf("push %d %d\n",i,  V_value[i]);
                PQ.push(make_pair(V_value[i] * (-1), i));
            }
        }

        int min_value;
        int min_index = NIL;
        while(!PQ.empty()){
            pair<int, int> p = PQ.top(); PQ.pop();
            //printf("pop %d %d\n", p.second, p.first * (-1));
            if(p.first * (-1) == V_value[p.second] && V[p.second] == WHITE){
                min_value = p.first * (-1);
                min_index = p.second;
                break;
            }
        }

        if(min_index == NIL)
            break;

        new_node = min_index;
        V[new_node] = BLACK;
        V_value[new_node] = min_value;
    }
    
    for(int i = 0; i < n; i++){
        printf("%d %d\n", i, V_value[i]);
    }

    return 0;
}

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