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 <iostream>
#include <vector>
#include <queue>

using namespace std;

const int INFTY = (1 << 30);

struct Node
{
    int node;
    int cost;
    Node(int n = 0, int c = INFTY) : node(n), cost(c) {}
};

bool operator<(const Node &n1, const Node &n2)
{
    return n1.cost < n2.cost;
}

class Dks
{
    vector<vector<int>> cost;
    vector<int> state, parent, dist;

public:
    Dks(int n = 0)
    {
        cost.resize(n);
        state.resize(n);
        parent.resize(n);
        dist.resize(n, INFTY);
    }

    void load_cost()
    {
        int node, n_v, v, c;
        for (int i = 0; i < cost.size(); i++)
        {
            cin >> node >> n_v;
            cost.at(node).resize(cost.size(), INFTY);
            for (int j = 0; j < n_v; j++)
            {
                cin >> v >> c;
                cost.at(node).at(v) = c;
            }
        }
    }

    void dks(int node)
    {
        int min_value;
        dist[node] = 0;
        while(true)
        {
            node = -1;
            min_value = INFTY;
            for(int i = 0;i<cost.size();i++){
                if(state[i] == 0 && dist[i] < min_value){
                    node = i;
                    min_value = dist[i];
                }
            }
            if(node == -1) break;
            state[node] = 1;

            for (int j = 0; j < cost.size(); j++)
            {
                if(cost[node][j] == INFTY) continue;
                if (state[j] == 0 && dist[j] > dist[node] + cost[node][j])
                {
                    dist[j] = dist[node] + cost[node][j];
                    parent[j] = node;
                }
            }
        }
    }

    void print(){
        for(int i=0;i<cost.size();i++){
            cout << i << " " << (dist[i] == INFTY ? -1 : dist[i]) << endl;
        }
    }
};

int main()
{
    int N;
    cin >> N;
    Dks dks(N);
    dks.load_cost();
    dks.dks(0);
    dks.print();
}

C++: #include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;

#define dump(x) cerr << #x << " : " << x << '\n'
#define MOD(x, y) (((y) + (x) % (y)) % (y))

int N;

int main(int argc, char* argv[])
{
	using COST_T = ll;
	using NODE_T = int;
	using PAIR_T = pair<COST_T, NODE_T>;

	struct Edge
	{
		NODE_T node;
		COST_T cost;
	};

	const int MAX_NODE_INDEX = 99;
	const COST_T INF_DIST = linf;
	vector<Edge> edges[MAX_NODE_INDEX + 1];
	COST_T dist_ar[MAX_NODE_INDEX + 1];

	scanf("%d", &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);
			edges[u].push_back( { v, c } );
		}
	}

	priority_queue<PAIR_T, vector<PAIR_T>, greater<PAIR_T>> pq;
	fill(dist_ar, dist_ar + MAX_NODE_INDEX + 1, INF_DIST);
	NODE_T st = 0;
	dist_ar[st] = 0;
	pq.push(PAIR_T(0, st));
	while(!pq.empty()) {
		COST_T temp_cost = pq.top().first;
		NODE_T node_index = pq.top().second;
		pq.pop();
		if (dist_ar[node_index] < temp_cost) continue;
		for (int next_list_index = 0; next_list_index < (int)edges[node_index].size(); next_list_index++) {
			COST_T new_cost = temp_cost + edges[node_index][next_list_index].cost;
			NODE_T next_index = edges[node_index][next_list_index].node;
			if (dist_ar[next_index] >= new_cost) {
				dist_ar[next_index] = new_cost;
				pq.push(PAIR_T(new_cost, next_index));
			}
		}
	}

	for (int i = 0; i < N; i++) {
		printf("%d %lld\n", i, dist_ar[i]);
	}

	return 0;
}

C++: #include <iostream>
#include<cstdio>
using namespace std;
const int INF = (1 << 21);
static int G[100][100];

void AskSSSP(int n){
    
    const int BLACK = 2,GRAY = 1,WHITE =  0;
    int color[n],d[n];
    for(int i = 0;i < n;++i){
        d[i] = INF;
        color[i] = WHITE;
    }
    d[0] = 0;
    int min,u;
    while(1){
        int min = INF;
        for(int i=0;i < n;++i){
            if(color[i] != BLACK && d[i] < min){
                min = d[i];
                u = i;
            }
        }
        if(min == INF) break;
        color[u] = BLACK;
        for(int i=0;i < n;++i){
            if(color[i] != BLACK && G[u][i] != INF){
                if(d[u] + G[u][i] < d[i]){
                    d[i] = d[u] + G[u][i];
                    color[i] = GRAY;
                }
            }
        }
        
    }
    for(int i = 0;i < n;++i) printf("%d %d\n",i,d[i]);

}

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