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 <limits.h>
#include <vector>
#include <queue>

using namespace std;

struct Node {
    int cost = INT_MAX;
    int color = 0;
    vector<int> next_node;
    vector<int> len_cost;
} node[100];

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

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> id >> k;
        node[id].next_node.resize(k);
        node[id].len_cost.resize(k);
        for (int j = 0; j < k; j++) {
            cin >> node[id].next_node[j] >> node[id].len_cost[j];
        }
    }

    int size1, size2;
    vector<int> vec;
    node[0].cost = 0;
    node[0].color = 1;
    vec.push_back(0);
    while (1) {
        size1 = vec.size();
        if (size1 == n) {
            break;
        }
        for (int i = 0; i < size1; i++) {
            size2 = node[vec[i]].next_node.size();
            for (int j = 0; j < size2;) {
                if (node[node[vec[i]].next_node[j]].cost > node[vec[i]].cost + node[vec[i]].len_cost[j]) {
                    node[node[vec[i]].next_node[j]].cost = node[vec[i]].cost + node[vec[i]].len_cost[j]; //????????????????????\????????\??????
                    j++;
                }
                else if (node[node[vec[i]].next_node[j]].cost < node[vec[i]].cost + node[vec[i]].len_cost[j]) { //?°????????????¨??????????????????????????¨??????
                    node[vec[i]].next_node.erase(node[vec[i]].next_node.begin() + j);
                    node[vec[i]].len_cost.erase(node[vec[i]].len_cost.begin() + j);
                    size2--;
                }
                else {
                    j++;
                }
            }
        }
        //?????\??????????????????????????????
        int min = INT_MAX, mini;
        for (int i = 0; i < size1; i++) {
            size2 = node[vec[i]].next_node.size();
            for (int j = 0; j < size2; j++) {
                if (min > node[node[vec[i]].next_node[j]].cost && node[node[vec[i]].next_node[j]].color == 0) {
                    min = node[node[vec[i]].next_node[j]].cost;
                    mini = node[vec[i]].next_node[j];
                }
            }
        }
        vec.push_back(mini);
        node[mini].color = 1;
    }

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

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
string u="abcdefghijklmnopqrstuvwxyz";

struct edge {int to;LL cost;};

const int M_N=10000;

vector<edge> G[M_N+1];
LL d[M_N+1];

struct Dijkstra{

    void dijkstra(int s){
        priority_queue<P,vector<P>,greater<P>> que;
        que.push(P(0,s));
        while(!que.empty()){
            P p=que.top();
            que.pop();
            int v=p.second;
            if(d[v]<p.first) continue;
            for(int i=0;i<G[v].size();i++){
                edge e=G[v][i];
                if(d[e.to]>d[v]+e.cost){
                    d[e.to]=d[v]+e.cost;
                    que.push(P(d[e.to],e.to));
                }
            }
        }
    }

};

int main(){
    Dijkstra Ds;
    fill(d,d+M_N+1,LINF);
    d[0]=0;
    int N;
    cin >> N;
    int u,k,v,c;
    while(cin >> u >> k){
        for(int i=0;i<k;i++){
            cin >> v >> c;
            G[u].push_back({v,c});
        }
    }
    Ds.dijkstra(0);
    for(int i=0;i<N;i++){
        cout << i <<" "<< d[i] << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
#define max 10000
#define infty 1<<21

int n;
int d[max];
int color[max];
vector<vector<int> > v(max);

void soya() {
	d[0] = 0;
	while (1) {
		int x = infty;
		for (int i = 0; i < n; i++) {
			if (x != infty) {
				if (d[i] < d[x] && color[i] != 2) {
					x = i;
				}
			}
			else {
				if (d[i] < x && color[i] != 2) {
					x = i;
				}
			}
		}

		if (x == infty) break;
		else {
			color[x] = 2;
			for (int i = 0; i < v[x].size() / 2; i++) {
				if (d[x] +v[x][(2 * i) + 1] < d[v[x][2 * i]]) {
					d[v[x][2 * i]] = d[x] + v[x][(2 * i) + 1];
				}
			}
		}
	}
}

int main() {
	for (int i = 0; i < max; i++) {
		color[i] = 0;
		d[i] = infty;
	}

	cin >> n;
	for (int i = 0; i < n; i++) {
		int id;
		int k;
		cin >> id >> k;
		for (int j = 0; j < k; j++) {
			int num1;
			int kyori;
			cin >> num1 >> kyori;
			v[id].push_back(num1);
			v[id].push_back(kyori);
		}
	}

	soya();

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

	return 0;
}