Go: package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

//make priority queue
type Item struct {
	id       int
	priority int // this state is priority and distans from start
	index    int
}

type PriorityQueue []*Item

func (pq PriorityQueue) Len() int { return len(pq) }

// we want the ascending-priority-queue.
// So we use less than here.
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 = j
	pq[j].index = i
}

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
}

func (pq *PriorityQueue) update(dist int, id int) {
	for _, i := range *pq {
		if i.id == id {
			if i.priority > dist {
				i.priority = dist
			}
		}
	}
}

// the main code
func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

func dikstra(dist [][]int, n int) []int {
	// preparate priority queue
	inf := 1 << 30
	pq := make(PriorityQueue, n)
	shortests := make([]int, n)
	for i := 0; i < n; i++ {
		pq[i] = &Item{
			id:       i,
			priority: inf,
			index:    i,
		}

		shortests[i] = inf
	}
	pq[0].priority = 0
	shortests[0] = 0

	for pq.Len() > 0 {
		item := heap.Pop(&pq).(*Item)
		shortests[item.id] = item.priority
		for id, d := range dist[item.id] {
			if d != -1 {
				pq.update(item.priority+d, id)
			}
		}
		heap.Init(&pq)
	}
	return shortests
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	// init
	n := nextInt(sc)
	dist := make([][]int, n)
	for i := 0; i < n; i++ {
		dist[i] = make([]int, n)
		for j := 0; j < n; j++ {
			dist[i][j] = -1
		}
	}

	// std Input
	for i := 0; i < n; i++ {
		u := nextInt(sc)
		k := nextInt(sc)
		for j := 0; j < k; j++ {
			v, c := nextInt(sc), nextInt(sc)
			dist[u][v] = c
		}
	}

	shortests := dikstra(dist, n)
	for i, d := range shortests {
		fmt.Printf("%d %d\n", i, 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);
}