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 <bits/stdc++.h>
using namespace std;

#define rep(i, n) REP(i, 0, n)
#define REP(i,k,n) for(int i = k; i < n; i++)
#define mmax(start, end) *max_element(start, end)
#define mmin(start, end) *min_element(start, end)
#define argmax max_element
#define argmin min_element
#define push push_back
#define pop pop_back
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef string str;

int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

template<class T = ll> T in() {
    T _in;
    cin >> _in;
    return _in;
}

#define EMAX 10000000

int cost[101][101];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n=in();
    ll d[101];

    rep(i, n) {
        rep(j, n) {
            cost[i][j] = EMAX;
        }
        d[i] = EMAX;
    }

    rep(i, n) {
        int u=in<int>(), k=in<int>();
        rep(j, k) {
            int v=in<int>(), c=in<int>();
            cost[u][v] = c;
        }
    }

    // ノード0からの距離を調べる
    d[0] = 0;
    bool flag = true;
    while(flag) {
        flag=false;
        // 移動する方法のある全ノードからの，次のノードへの移動コストを考える
        rep(i, n) {
            if(d[i] != EMAX) {
                rep(j, n) {
                    if(i == j)
                        continue;
                    int next_c = d[i] + cost[i][j];

                    // 更新できる場合更新
                    if(d[j] > next_c) {
                        d[j] = next_c;
                        flag=true;
                    }
                }
            }
        }
    }

    rep(i, n) {
        cout << i << " " << d[i] << endl;
        // rep(j, n) {
        //     cout << cost[i][j] << " ";
        // }
        // cout << endl;
    }
    
    return 0;
}

C++: #include<iostream>
#include<vector>
#define N 101
using namespace std;
int n;
vector<int> D(N,1<<30);
//bool visited[N];
vector<bool> visited(N,0);
vector<int> pre(N,0);
vector<vector<int>> M(N,vector<int>(N,0));
//int M[N][N];

void dijkstra(){
    D[0]=0;
    pre[0]=-1;

    while(1){
        int minD=1<<30;
        int u=-1;
        for(int i=0;i<n;i++){
            if(visited[i]) continue;
            if(D[i]<minD){
                u=i;
                minD=D[i];
            }
        }
        if(u==-1) break;

        visited[u]=1;
        for(int i=0;i<n;i++){
            if(visited[i]) continue;
            if(M[u][i]>0 && D[i]>D[u]+M[u][i]){
                D[i]=D[u]+M[u][i];
                pre[i]=u;
            }
        }

    }
}

void init(){
    cin>>n;
    int u,k,c,v;
    for(int i=0;i<n;i++){
        /*for(int j=0;j<n;j++){
            M[i][j]=0;
        }*/
        visited[i]=false;
        cin>>u>>k;
        for(int j=0;j<k;j++){
            cin>>v>>c;
            M[u][v]=c;
        }
    }
}

int main(){
    init();
    /*for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cout<<M[i][j]<<' ';
        }
        cout<<endl;
    }*/
    dijkstra();
    for(int i=0;i<n;i++){
        cout<<i<<' '<<D[i]<<endl;
    }
    return 0;
}

/*
5
0 3 2 3 3 1 1 2
1 2 0 2 3 4
2 3 0 3 3 1 4 1
3 4 2 1 0 1 1 4 4 3
4 2 2 1 3 3
*/

C++: #include<stdio.h>
using namespace std;
const int maxn=1<<21;
int n;
int a[105][105];
void dan()
{
    int minx;
    int d[105],color[105];
    for(int i=0;i<n;i++)
    {
        d[i]=maxn;
        color[i]=0;
    }
    d[0]=0;
    while(1)
    {
        minx=maxn;
        int u=-1;
        for(int i=0;i<n;i++)
        {
            if(d[i]<minx&&color[i]!=1)
            {
                minx=d[i];
                u=i;
            }
        }
        if(u==-1) break;
        color[u]=1;
        for(int i=0;i<n;i++)
        {
            if(color[i]==1||a[u][i]==maxn) continue;
            if(d[i]>d[u]+a[u][i])
            {
                d[i]=d[u]+a[u][i];

            }
        }
    }
    for(int i=0;i<n;i++)
    {
        printf("%d ",i);
        printf("%d\n",(d[i]==maxn)?-1:d[i]);
    }
}
int main()
{
    scanf("%d",&n);
    for(int i=0;i<105;i++)
    {
        for(int j=0;j<105;j++)
        {
            a[i][j]=maxn;
        }
    }
    int k,c,u,v;
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&k,&c);
        for(int j=0;j<c;j++)
        {
            scanf("%d%d",&u,&v);
            a[k][u]=v;
        }
    }
    dan();
    return 0;
}