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<iostream>
#include<cstdio>
using namespace std;
static const int INFTY=(1<<21);
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;
int n,H[100][100];
void dd()
{
    int minv;
    int d[100],c[100];
    for(int i=0;i<n;i++)
    d[i]=INFTY;
    d[0]=0;
    while(1)
    {
        minv=INFTY;
        int u=-1;
        for(int i=0;i<n;i++)
        {
            if(minv>d[i]&&c[i]!=BLACK)
            {
                u=i;
                minv=d[i];
            }
        }
        if(u==-1) break;
        c[u]=BLACK;
        for(int v=0;v<n;v++)
        {
            if(c[v]!=BLACK&&H[u][v]!=INFTY)
            {
                if(d[v]>d[u]+H[u][v])
                {
                    d[v]=d[u]+H[u][v];
                    c[v]=GRAY;
                }
            }
        }
    }
    for(int i=0;i<n;i++)
            printf("%d %d\n",i,(d[i]==INFTY?-1:d[i]));
}
int main()
{
    int a,b,c,d;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
        H[i][j]=INFTY;
    for(int i=0;i<n;i++)
    {
        scanf("%d %d",&a,&b);
        for(int j=0;j<b;j++)
        {
            scanf("%d %d",&c,&d);
            H[a][c]=d;
        }
    }
    dd();
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
static const int MAX=10000;
static const int INFTY=2000000000;

vector<pair<int,int> > A[MAX];
int dk[MAX],H[MAX+1],tail,where[MAX];

void cminHeap(int i){
    int left,right,least;
    left=2*i;right=left+1;least=i;
    if(left<=tail&&dk[H[left]]<dk[H[i]])least=left;
    if(right<=tail&&dk[H[right]]<dk[H[least]])least=right;
    if(i==least)return;
    swap(H[i],H[least]);swap(where[H[i]],where[H[least]]);
    cminHeap(least);
}

void pminHeap(int i){
    int parent=i/2;
    if(parent==0||dk[H[parent]]<=dk[H[i]])return;
    swap(H[parent],H[i]);swap(where[H[parent]],where[H[i]]);
    pminHeap(parent);
}

void heap_update(int u){
    int x=H[u];
    cminHeap(u);
    if(H[u]==x)pminHeap(u);
}

void SSSP(int n){
    for(int i=0;i<n;i++){
        dk[i]=INFTY;
        H[i+1]=i;
        where[i]=i+1;
    }
    dk[0]=0;
    tail=n;
    int v;
    while(tail>0){
        v=H[1];H[1]=H[tail];where[H[tail]]=1;
        tail--;where[v]=-1;
        cminHeap(1);
        vector<pair<int,int> >::iterator it;
        for(it=A[v].begin();it<A[v].end();it++){
            pair<int,int> item=*it;
            if(where[item.first]!=-1){
                if(dk[item.first]>dk[v]+item.second){
                    dk[item.first]=dk[v]+item.second;
                    heap_update(where[item.first]);
                }
            }
        }
    }
}

int main(){
    int n,v,k,u,d;
    cin>>n;
    for(int i=0;i<n;i++){
        scanf("%d %d",&v,&k);
        for(int j=0;j<k;j++){
            scanf("%d %d",&u,&d);
            A[v].push_back(make_pair(u,d));
        }
    }
    SSSP(n);
    for(int i=0;i<n;i++)printf("%d %d\n",i,dk[i]);
}

C++: #include<iostream>
#include<vector>
#include<queue>
using namespace std;
struct Edge {
    int d, i, j;
    Edge(int d_, int i_, int j_) : d(d_), i(i_), j(j_) {}
    bool operator< (const Edge& right) const{
        return d > right.d;
    }
};
void calc(int t, vector<vector<int> >& G, vector<int>& distance){
    int new_black = t;
    priority_queue<Edge> temp;
    for (int i = 1; i < G.size(); i++) {
        for (int j = 0; j < G.size(); j++) {
            if (distance[j] != -1) continue;
            int dis = G[new_black][j] + distance[new_black];
            temp.push(Edge(dis, new_black, j));
        }
        while (distance[temp.top().j] != -1) temp.pop();
        distance[temp.top().j] = temp.top().d;
        new_black = temp.top().j;
        temp.pop();
    }
}

int main(){
    int n;
    cin >> n;
    vector<vector<int> > G(n, vector<int>(n, 1e8));
    for (int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int c, v;
            cin >> c >> v;
            G[u][c] = v;
        }
    }

    vector<int> distance(n, -1);
    distance[0] = 0;
    calc(0, G, distance);
    for (int i = 0; i < n; i++) {
        cout << i << " " << distance[i] << endl;
    }
    return 0;
}