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>
#include<limits.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)

#define INF INT_MAX

#define MAX 10000
vector<vector<pair<int, int>>> adj_list(MAX);

void dijkstra(int start_node, int node_size){
    vector<int> visited(node_size, 0);
    vector<int> cost_table(node_size, INF);

    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
    
    visited.at(start_node) = 1;
    cost_table.at(start_node) = 0;
    //queueの初期化 startノードに隣接するノードとそのコストをpush
    // cout << "queue pushed : ";
    int i = 0;
    while(adj_list.at(start_node).at(i).first != -1){
        pair<int, int> x = make_pair(adj_list.at(start_node).at(i).second, adj_list.at(start_node).at(i).first);
        q.push(x);
        // cout << x.first << " " << x.second << "  ";
        cost_table.at(x.second) = x.first;
        i++;
    }
    // cout << endl;

    // cout << "cost_table ====" << endl;
    // rep(i, node_size) cout << i << " " << cost_table.at(i) << endl;
    // cout << endl;


    while(q.size() != 1){
        pair<int, int> Nnode = q.top(); q.pop();
        int nearestNode = Nnode.second;

        visited.at(nearestNode) = 1;

        int i = 0;

        while(adj_list.at(nearestNode).at(i).first != -1){
            int v = adj_list.at(nearestNode).at(i).first; // 構築中の木に隣接するノードvと、追加したノード(nearestNode)からのコストc
            int c = adj_list.at(nearestNode).at(i).second;// 

            // cout << "nearest node : " << nearestNode << " " << v << " " << c << endl;

            if(visited.at(v) == 1){
                // cout << "old" << endl;
                i++;
                continue;
            }else{
                // cout << "new : cost_table " << cost_table.at(v) << " " <<  cost_table.at(nearestNode) << endl;

                if(cost_table.at(v) > cost_table.at(nearestNode) + c){
                    cost_table.at(v) = cost_table.at(nearestNode) + c;
                    q.push(make_pair(cost_table.at(v), v));
                    // cout << "queue pushed : cost " << cost_table.at(v) << " node " << v << endl; 
                }
            }
            i++;
        }
    }

    rep(i, node_size){
        cout << i << " " << cost_table.at(i) << endl;
    }
}



int main(){
    int n; cin >> n;

    //　隣接リストの作成
    rep(i, n){
        int from, k; cin >> from >> k;

        rep(j, k){
            int to, weight; cin >> to >> weight;
            adj_list.at(from).push_back(make_pair(to, weight));
        }
    }

    //番兵の挿入
    rep(i, n){
        adj_list.at(i).push_back(make_pair(-1, -1));
    }

    // cout << endl;
    // rep(i, n){
    //     int j = 0;
    //     while(adj_list.at(i).at(j).first != -1){
    //         cout << adj_list.at(i).at(j).first << " " << adj_list.at(i).at(j).second << " ";
    //         j++;
    //     }
    //     cout << endl;
    // }

    dijkstra(0, n);

}

C++: #include<iostream>
using namespace std;
#include<cstdio>
#include<vector>
#include<utility>
#include<queue>

typedef vector<pair<int, int> > adj;

struct current_cost
{
	int index, cost;
	bool operator < (const current_cost &cur) const
	{
		return cost < cur.cost;
	}
};

current_cost init(int i, int c)
{
	current_cost cur;
	cur.index = i, cur.cost = c;
	return cur;
}

int main()
{
	int i, j, k, n, m, next, cost;
	scanf("%d", &n);
	adj *adlist;
	adlist = new adj [n];

	for(k = 0; k < n; k++){
		scanf("%d %d", &i, &m);
		for(j = 0; j < m; j++){
			scanf("%d %d", &next, &cost);
			adlist[i].push_back(make_pair(next, cost));
		}
	}
	
	int *d;
	d = new int [n];
	d[0] = 0;
	for(i = 1; i < n; i++){
		d[i] = 200000;
	}

	priority_queue<current_cost> C;
	current_cost cur = init(0, 0);
	C.push(cur);

	int size;
	bool *check;
	check = new bool [n];
	for(i = 0; i < n; i++){ check[i] = false; }

	while(!C.empty())
	{
		cur = C.top(); C.pop();
		if(check[cur.index]) continue;
		check[cur.index] = true;

		i = cur.index;
		size = adlist[i].size();
		for(j = 0; j < size; j++){
			k = adlist[i][j].first;
			if(d[i] + adlist[i][j].second < d[k]){
				d[k] = d[i] + adlist[i][j].second;
				C.push(init(k, d[k]));
			}
		}
	};
	for(i = 0; i < n; i++){ printf("%d %d\n", i, d[i]); }

	return 0;
}

C++: #include<stdio.h>
#include<queue>
#include<algorithm>
#include<vector>
using namespace std;
int maxn=1<<30;
int n;
int color[10005];
int d[10005];
vector<pair<int, int> > bian[10005];
int f()
{
    priority_queue<pair<int ,int > > pq;
    for(int i=0;i<n;i++)
    {
        d[i]=maxn;
    }
    d[0]=0;
    pq.push(make_pair(0,0));
    while(!pq.empty())
    {
        pair<int ,int > x=pq.top();
        pq.pop();
        int u=x.second;
        color[u]=1;
        if(d[u]<x.first *(-1)) continue;
        for(int i=0;i<bian[u].size();i++)
        {
            int v=bian[u][i].first;
            if(color[v]==1) continue;
            if(d[v]>(d[u]+bian[u][i].second))
            {
                d[v]=d[u]+bian[u][i].second;
                pq.push(make_pair(d[v]*(-1),v));
                color[v]=0;
            }
        }
    }
    for(int i=0;i<n;i++)
    {
        printf("%d ",i);
        printf("%d\n",(d[i]==maxn)?-1:d[i]);
    }
}
int main()
{
    int k,u,c,g;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&k,&u);
        for(int j=0;j<u;j++)
        {
            scanf("%d%d",&c,&g);
            bian[k].push_back(make_pair(c,g));
        }
    }
    f();
    return 0;
}