Go: package main

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

//make priority queue
type Item struct {
	id       int
	priority int // this state is priority and distans from start
	index    int
}

type PriorityQueue []*Item

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

// we want the ascending-priority-queue.
// So we use less than here.
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 = j
	pq[j].index = i
}

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
}

func (pq *PriorityQueue) update(dist int, id int) {
	for _, i := range *pq {
		if i.id == id {
			if i.priority > dist {
				i.priority = dist
			}
		}
	}
}

// the main code
func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

func dikstra(dist [][]int, n int) []int {
	// preparate priority queue
	inf := 1 << 30
	pq := make(PriorityQueue, n)
	shortests := make([]int, n)
	for i := 0; i < n; i++ {
		pq[i] = &Item{
			id:       i,
			priority: inf,
			index:    i,
		}

		shortests[i] = inf
	}
	pq[0].priority = 0
	shortests[0] = 0

	for pq.Len() > 0 {
		item := heap.Pop(&pq).(*Item)
		shortests[item.id] = item.priority
		for id, d := range dist[item.id] {
			if d != -1 {
				pq.update(item.priority+d, id)
			}
		}
		heap.Init(&pq)
	}
	return shortests
}

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

	// init
	n := nextInt(sc)
	dist := make([][]int, n)
	for i := 0; i < n; i++ {
		dist[i] = make([]int, n)
		for j := 0; j < n; j++ {
			dist[i][j] = -1
		}
	}

	// std Input
	for i := 0; i < n; i++ {
		u := nextInt(sc)
		k := nextInt(sc)
		for j := 0; j < k; j++ {
			v, c := nextInt(sc), nextInt(sc)
			dist[u][v] = c
		}
	}

	shortests := dikstra(dist, n)
	for i, d := range shortests {
		fmt.Printf("%d %d\n", i, d)
	}
}

C++: #include <bits/stdc++.h>

using namespace std;

vector<pair<int, int>> adja[10000];

#define INF (1 << 30)

int main() {
	int n, id, k, a, b;

	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> id >> k;
		for (int j = 0; j < k; ++j) {
			cin >> a >> b;
			adja[id].push_back(make_pair(a, b));
		}
	}

	priority_queue<pair<int, int>> que;
	que.push(make_pair(0, 0)); //cost, node
	int cost[10000];
	fill(cost, cost + n, INF);

	while (!que.empty()) {
		for (int i = 0, size = que.size(); i < size; ++i) {
			pair<int, int> top = que.top();
			que.pop();

			if (cost[top.second] < top.first) {
				continue;
			}
			cost[top.second] = top.first;

			for (int j = 0, len = adja[top.second].size(); j < len; ++j) {
				que.push(make_pair(top.first + adja[top.second][j].second, adja[top.second][j].first));
			}
		}
	}

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

	return 0;
}

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