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 <array>
#include <algorithm>
#include <limits>
#include <cmath>
#include <numeric>
#include <string>
#include <queue>

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
#define rep(i, a, b) for(int i = (a); i < (b); ++i )
#define rrep(i, a, b) for(int i = (a); i > (b); --i )
#define REP(i, a, b) for(int i = (a); i <= (b); ++i )
#define RREP(i, a, b) for(int i = (a); i >= (b); --i )
#define llrep(i, a, b) for(ll i = (a); i < (b); ++i )
#define llrrep(i, a, b) for(ll i = (a); i > (b); --i )
#define llREP(i, a, b) for(ll i = (a); i <= (b); ++i )
#define llRREP(i, a, b) for(ll i = (a); i >= (b); --i )
#define ullrep(i, a, b) for(ull i = (a); i < (b); ++i )
#define ullrrep(i, a, b) for(ull i = (a); i > (b); --i )
#define ullREP(i, a, b) for(ull i = (a); i <= (b); ++i )
#define ullRREP(i, a, b) for(ull i = (a); i >= (b); --i )

template<typename T=int>
class UnionFind {
public:
    explicit UnionFind(unsigned long long n) : rank_(n, 0), p_(n, 0) {
        for (T i = 0; i < n; i++) {
            MakeSet(i);
        }
    }

    void MakeSet(T x) {
        p_[x] = x;
        rank_[x] = 0;
    }

    bool Same(T x, T y) {
        return FindSet(x) == FindSet(y);
    }

    void Link(T x, T y) {
        if (rank_[x] > rank_[y]) {
            p_[y] = x;
        } else {
            p_[x] = y;
            if (rank_[x] == rank_[y]) {
                rank_[y]++;
            }
        }
    }

    void Unite(T x, T y) {
        Link(FindSet(x), FindSet(y));
    }

    T FindSet(T x) {
        if (x != p_[x]) {
            p_[x] = FindSet(p_[x]);
        }
        return p_[x];
    }

private:
    std::vector<T> rank_, p_;
};
template<typename NumT = ull, typename CostT = ull>
class Dijkstra {
public:
    Dijkstra(unsigned long long num, CostT max_cost) :
            num_(num),
            max_cost_(max_cost),
            v_(num, std::vector<CostT>(num, max_cost)),
            c_(num, 0),
            d_(num, max_cost),
            p_(num, 0) {
    };


    void ComputeWithQ(NumT start) {
        d_[start] = 0;
        p_[start] = start;
        priority_queue<std::pair<CostT, NumT>> pq;
        pq.push(make_pair(0, start));
        while (!pq.empty()) {
            auto node = pq.top();
            pq.pop();
            auto ni = node.second;
            auto c = -node.first;
            c_[ni] = 1;
            if (d_[ni] < c) {
                continue;
            }
            d_[ni] = c;

            for (int i = 0; i < num_; i++) {
                if(v_[ni][i] == max_cost_) {
                    continue;
                }
                if ((c_[i] != 1) && (d_[i] > (v_[ni][i] + d_[ni]))) {
                    p_[i] = ni;
                    d_[i] = v_[ni][i] + d_[ni];
                    pq.push(make_pair(-d_[i], i));
                }
            }
        }
    }

    void Compute(int start) {
        d_[start] = 0;
        p_[start] = start;
        while (true) {
            int m = -1;
            int min_d = std::numeric_limits<int>::max();
            for (int i = 0; i < num_; i++) {
                if ((c_[i] == 0) && (min_d > d_[i])) {
                    min_d = d_[i];
                    m = i;
                }
            }
            if (m < 0) {
                break;
            }
            c_[m] = 1;
            for (int i = 0; i < num_; i++) {
                if ((c_[i] == 0) && (d_[i] > (d_[m] + v_[m][i])) ) {
                    d_[i] = d_[m] + v_[m][i];
                    p_[i] = m;
                }
            }
        }
    }

    void Set(NumT s, NumT d, CostT c) {
        v_[s][d] = c;
    }

    CostT Distance(NumT d) {
        return d_[d];
    }

public:
    NumT num_;
    CostT max_cost_;
    std::vector<std::vector<CostT>> v_;
    std::vector<int> c_;
    std::vector<int> d_;
    std::vector<NumT> p_;
};
int nibutan(int *ary, int ok, int ng) {
    bool is_valid;
    while ( std::abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;
        // is_valid = check(mid);
        if (is_valid) {
            ok = mid;
        }else{
            ng = mid;
        }
    }
    return ok;
}

template<typename NumT = int, typename CostT = unsigned long long>
class DijkstraQ {
public:
    DijkstraQ(unsigned long long num, CostT max_cost):
    adj_(num, std::vector<std::pair<NumT, CostT>>()),
    c_(num, 0),  d_(num, max_cost)
    {}

    void Compute(NumT start) {
        std::priority_queue<std::pair<CostT, NumT>> q;
        d_[start] = 0;
        q.push(std::make_pair(0, start));

        while(!q.empty()) {
            std::pair<CostT, NumT> node = q.top();
            q.pop();
            auto n = node.second;
            auto c = -node.first;
            c_[n] = 1;
            if (c > d_[n]) {
                continue;
            }
            d_[n] = c;

            for (NumT i = 0; i < adj_[n].size(); i++) {
                auto nn = adj_[n][i].first;
                auto nc = adj_[n][i].second;
                if (c_[nn] > 0) {
                    continue;
                }
                if (d_[nn] > (c + nc)) {
                    d_[nn] = c + nc;
                    q.push(std::make_pair(-d_[nn], nn));
                }
            }
        }
    }

    void Set(NumT s, NumT d, CostT c) {
        adj_[s].push_back(std::make_pair(d, c));
    }

    CostT Distance(NumT d) {
        return d_[d];
    }

    std::vector<CostT> d_;
    std::vector<int> c_;
    std::vector<std::vector<std::pair<NumT, CostT>>> adj_;
};


bool check(int *A, int i) {
    return A[i] < 39;
}
int nibutan(int *A) {
    int ok = 0;
    int ng = 100;
    while (ng - ok > 1) {
        cout << ng << ", " << ok << endl;
        if (check(A, (ng + ok) / 2)) {
            ok = (ng + ok) / 2;
        }else{
            ng = (ng + ok) / 2;
        }
    }
    return ok;
}

ull K;
ull A[200010];
ull L[200010];
ull R[200010];

double f(ull N) {
    ull ret = 0;
    while(N) {
        ret += N%10;
        N /= 10;
    }
    return double(N) / ret;
}


ull N;
constexpr ull MAXCOST = 1000000000000000;

int main() {
    cin >> N;
    Dijkstra<ull, ull> dq(N+1, MAXCOST);
    rep(i, 0, N) {
        ull n, num;
        cin >> n >> num;
        rep(j, 0, num) {
            ull d, c;
            cin >> d >> c;
            dq.Set(n, d, c);
        }
    }
    dq.ComputeWithQ(0);
    rep(i, 0, N) {
        cout << i << " " << dq.Distance(i) << endl;
    }
}