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++: #define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#define ll long long
#define str string
#define ld long double
#define vec vector
#define vll vec<ll>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(ll i=b;i>=a;i--)
#define ALL(a) a.begin(),a.end()
#define rALL(a) a.rbegin(),a.rend()
#define kai "\n"
#define yuque priority_queue
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mie min_element
#define mae max_element
#define tos to_string
#define sep setprecision
#define lob lower_bound
#define upb upper_bound
#define nep next_permutation
#define MOD 1000000007ll
#define MIN (1e-10)
#define equal(a,b) (abs((a)-(b))<MIN)
#define v2 ten
#define chokusen senbun
#define kakkei vec<ten>
using namespace std;
void solve();
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed;
	solve();
}
struct pea{
	ll f,s;
	bool operator<(const pea &p)const{
		return f!=p.f?f<p.f:s<p.s;
	};
};
struct tri{
	ll f,s,t;
	bool operator<(const tri &p)const{return f<p.f;};
};
class ten{
public:
	ld x,y;
	ten operator+(ten p){return{x+p.x,y+p.y};}
	ten operator-(ten p){return{x-p.x,y-p.y};}
	ten operator*(ld k){return{k*x,k*y};}
	ten operator/(ld k){return{x/k,y/k};}
	ld abs(){return sqrt(abs2());}
	ld abs2(){return x*x+y*y;};
	bool operator<(const ten &p)const{return x!=p.x?x<p.x:y<p.y;};
	bool operator==(const ten &p)const{
		return (-MIN<x-p.x)&&(x-p.x<MIN)&&(-MIN<y-p.y)&&(y-p.y<MIN);
	};
	ld naiseki(v2 b){return x*b.x+y*b.y;}
	ld gaiseki(v2 b){return x*b.y-y*b.x;}
};
struct senbun{ten p1,p2;};
struct en{ten o;ld r;};
void dijkstra(const vec<vec<pea>> &c,ll v,vll &d){
	d[v]=0;
	ll n=c.size();
	ll count=1;
	vec<bool> seen(n,false);
	seen[v]=true;
	yuque<pea> hen;
	rep(i,0,c[v].size())hen.push({-c[v][i].f,c[v][i].s});
	while(count!=n){
		pea k=hen.top();hen.pop();
		while(seen[k.s]){
			k=hen.top();
			hen.pop();
		}
		d[k.s]=-k.f;
		count++;
		seen[k.s]=true;
		rep(i,0,c[k.s].size())hen.push({k.f-c[k.s][i].f,c[k.s][i].s});
	}
}
void solve(){
	ll n;cin>>n;
	vec<vec<pea>> c(n);
	rep(i,0,n){
		ll u,k;
		cin>>u>>k;
		rep(j,0,k){
			ll v,w;
			cin>>v>>w;
			c[u].pub({w,v});
		}
	}
	vll ans(n);
	dijkstra(c,0,ans);
	rep(i,0,n)cout<<i<<' '<<ans[i]<<kai;
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

constexpr int LEN = 10005;
vector<P> a[LEN];

void dikstra(const int n){
	int d[n];
	bool check[n] = {0};
	memset(d, 1, sizeof(d));
	priority_queue<P, vector<P>, greater<P> > h;

	d[0] = 0;
	h.push(make_pair(d[0], 0));
	check[0] = 1;

	while(h.size()){
		P f = h.top(); h.pop();
		int u = f.second;
		int uc = f.first;
		check[u] = 1;
		for(P vf : a[u]){
			int v = vf.second;
			int vc = vf.first;
			if(!check[v]){
				if((uc + vc) < d[v]){
					d[v] = uc + vc;
					h.push(make_pair(d[v], v));
				}
			}
		}
	}

	rep(i, n) cout << i << ' ' << d[i] << endl;
	return;
}

int main(){
	int n; cin >> n;
	rep(i, n){
		int u, k; cin >> u >> k;
		rep(j, k){
			int v, c; cin >> v >> c;
			a[u].push_back(make_pair(c, v));
		}
	}

	dikstra(n);
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <queue>
using namespace std;

// first: cost, second: key
typedef pair<int, int> vert;

static const int MAX   = 10000;
static const int INFTY = 1 << 20;
static const int WHITE = 0;
static const int BLACK = 2;

vector<vert> adjs[MAX];

void dijkstra(int n_v, int v_start) {
    priority_queue< vert, vector<vert>, greater<vert> > visitings;
    int color[MAX];
    int costs[MAX];

    for (int i = 0; i < n_v; i++) {
        costs[i] = INFTY;
        color[i] = WHITE;
    }

    costs[v_start] = 0;
    visitings.push( make_pair(0, v_start) );

    while (! visitings.empty()) {
        vert nearest = visitings.top();
        visitings.pop();

        int next_id = nearest.second;
        color[next_id] = BLACK;

        if ( costs[next_id] < nearest.first )
            continue;

        for (int i = 0; i < adjs[next_id].size(); i++) {
            int adj  = adjs[next_id][i].first;
            int cost = adjs[next_id][i].second;

            if (color[adj] == BLACK)
                continue;

            if (costs[next_id] + cost < costs[adj]) {
                costs[adj] = costs[next_id] + cost;
                visitings.push( make_pair(costs[adj], adj) );
            }
        }
    }

    for (int i = 0; i < n_v; i++) {
        cout << i << " " << costs[i] << "\n";
    }
}

int main() {
    std::ios::sync_with_stdio(false);

    int n_v;
    cin >> n_v;

    for (int i = 0; i < n_v; i++) {
        int vert_id, n_adjs;
        cin >> vert_id >> n_adjs;

        for (int j = 0; j < n_adjs; j++) {
            int adj, cost;
            cin >> adj >> cost;
            adjs[vert_id].push_back( make_pair(adj, cost) );
        }
    }

    dijkstra(n_v, 0);
}