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 <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef pair<ll, ll> P;

ll squareDis(P x, P y){
    return (x.fs - y.fs) * (x.fs - y.fs) + (x.sc - y.sc) * (x.sc - y.sc);
}

bool judgeAcute(P x, P y, P z){
    ll dis1 = squareDis(x, y);
    ll dis2 = squareDis(x, z);
    ll dis3 = squareDis(y, z);

    return dis1 + dis2 > dis3;

}

class Graph{
    struct edge{
        int vertice;
        ll weight;
    };

    vector<vector<edge>> g;
    unsigned int n;

public:
    Graph(unsigned int n): n{n}{
        g.resize(n);
    }

    void add_edge(int u, int v){
        g[u].emplace_back(edge{v, 1});
    };

    void add_edge(int u, int v, ll w){
        g[u].emplace_back(edge{v, w});
    }

    vector<edge>& get_edge(int v){
        return g[v];
    }

    unsigned int get_num_vertices(){
        return n;
    }

    vector<edge>& operator[](int v){
        return get_edge(v);
    }
};


/**
 *
 * @param s 始点
 * @param g グラフ
 * @return sから各頂点への距離
 */
vector<ll> dijkstra1(int s, Graph g, ll INF=LONG_LONG_MAX / 3){
    unsigned int n = g.get_num_vertices();
    vector<bool> used(n, false);
    vector<ll> d(n, INF);

    d[s] = 0;
    while(true){
        int v = -1;
        for(int u = 0; u < n; u++) {
            if (!used[u] && (v == -1 || d[u] < d[v])) {
                v = u;
            }
        }

        if(v == -1) break;

        used[v] = true;
        for(auto e: g[v]){
            d[e.vertice] = min(d[e.vertice], d[v] + e.weight);
        }
    }

    return d;
}


vector<ll> dijkstra2(int s, Graph g, ll INF=LONG_LONG_MAX / 3){
    typedef pair<ll, int> Ptmp;  // firstは最短距離、secondは頂点の番号

    unsigned int n = g.get_num_vertices();
    priority_queue<Ptmp, vector<Ptmp>, greater<Ptmp>> que;
    vector<ll> d(n, INF);

    d[s] = 0;
    que.push(Ptmp(d[s], s));

    while(!que.empty()){
        Ptmp p = que.top();   que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        for(auto e: g[v]){
            if(d[e.vertice] > d[v] + e.weight){
                d[e.vertice] = d[v] + e.weight;
                que.push(Ptmp(d[e.vertice], e.vertice));
            }
        }
    }

    return d;
}



int main(){
    uint n;  cin >> n;
    Graph g(n);

    for(int i = 0; i < n; i++){
        int u, k;   cin >> u >> k;
        for(int j = 0; j < k; j++){
            int v, c;   cin >> v >> c;
            g.add_edge(u, v, c);
        }
    }

    vector<ll> res = dijkstra2(0, g);
    for(int i = 0; i < n; i++){
        cout << i << " " << res[i] << endl;
    }
}


//int main(){
//    int n, m;   cin >> n >> m;
//
//    vector<vector<edge>> g(100);
//    vector<P> cor(n);
//
//    for(int i = 0; i < n; i++){
//        int x, y;   cin >> x >> y;
//        cor[i] = P(x, y);
//    }
//    for(int i = 0; i < m; i++){
//        int a, b, c;    cin >> a >> b >> c;
//        a--; b--;
//        g[a].emplace_back(edge{c, b});
//        g[b].emplace_back(edge{c, a});
//    }
//
//    vector<vector<edge>> g2;
//    map<P, int> mp;
//    g2.emplace_back(vector<edge>(0));
//    int n2 = 0;
//    mp[P(0, 0)] = n2++;
//
//    for(int i = 0; i < n; i++){
//        for(auto v: g[i]){
//            g2.emplace_back(vector<edge>(0));
//            mp[P(i, v.v)] = n2++;
//        }
//    }
//
//    for(int i = 0; i < n; i++){
//        for(auto v: g[i]){
//            for(auto u: g[i]){
//                if(!judgeAcute(cor[i], cor[u.v], cor[v.v])){
//                    g2[mp[P(i, v.v)]].emplace_back(edge{u.w, mp[P(u.v, i)]});
//                }
//            }
//        }
//    }
//
//
//
//    return 0;
//}