Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const BIG_COST = 200000

type Path struct {
	node int
	cost int
}

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

	nNodes := scanInt(sc)

	// 各頂点につながる頂点一覧を得るための隣接リスト
	graph := make([][]Path, nNodes)

	for i := 0; i < nNodes; i++ {
		u := scanInt(sc)
		k := scanInt(sc)
		graph[i] = make([]Path, k)
		for d := 0; d < k; d++ {
			graph[u][d] = Path{
				node: scanInt(sc),
				cost: scanInt(sc),
			}
		}
	}

	// 0 から各頂点への最小コストを保存する配列
	minCosts := make([]int, nNodes)

	minCosts[0] = 0
	for i := 1; i < nNodes; i++ {
		minCosts[i] = BIG_COST
	}

	// 各頂点が調査済みかどうかを保持する配列
	checked := make([]bool, nNodes)

	// 最小コストのパスを高速に取得するためのヒープ。
	// コストが小さいものほどルートに来るようにする。
	heap := NewHeap(func(a, b Path) bool {
		return a.cost < b.cost
	})

	heap.insert(Path{node: 0, cost: 0})
	for heap.size > 0 {
		u := heap.extractMax()

		// 隣接行列を使っていた時とは違い、ヒープには
		// 同じノードへのパスが複数含まれうる。そのため既によりコストの低い
		// パスが見つかっている場合は無視する。
		if minCosts[u.node] < u.cost {
			continue
		}

		checked[u.node] = true

		for _, v := range graph[u.node] {
			cost := v.cost + u.cost
			if !checked[v.node] && cost < minCosts[v.node] {
				minCosts[v.node] = cost
				heap.insert(Path{node: v.node, cost: cost})
			}
		}
	}

	w := bufio.NewWriter(os.Stdout)
	for i, cost := range minCosts {
		fmt.Fprintf(w, "%d %d\n", i, cost)
	}
	w.Flush()
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

// --- From ALDS1_9_C: Priority Queue

type Heap struct {
	size   int
	heap   []Path
	isHigh func(a, b Path) bool
}

func NewHeap(isHigh func(a, b Path) bool) Heap {
	heap := make([]Path, 1) // 先頭は不使用
	return Heap{size: 0, heap: heap, isHigh: isHigh}
}

func (h *Heap) insert(v Path) {
	h.size += 1
	if h.size > len(h.heap)-1 {
		h.heap = append(h.heap, v)
	} else {
		h.heap[h.size] = v
	}

	for i := h.size; i > 1; {
		parent := i / 2
		if h.isHigh(h.heap[parent], h.heap[i]) {
			break
		}
		h.heap[i], h.heap[parent] = h.heap[parent], h.heap[i]
		i = parent
	}
}

func (h *Heap) extractMax() Path {
	if h.size <= 0 {
		panic("cannot extract from empty heap")
	}

	max := h.heap[1]
	h.heap[1] = h.heap[h.size]
	h.size -= 1
	h.maxHeapify(1)

	return max
}

func (h *Heap) maxHeapify(idx int) {
	left := idx * 2
	right := left + 1
	largest := idx

	if left <= h.size {
		if h.isHigh(h.heap[left], h.heap[idx]) {
			largest = left
		}
		if right <= h.size && h.isHigh(h.heap[right], h.heap[largest]) {
			largest = right
		}
	}

	if largest != idx {
		h.heap[idx], h.heap[largest] = h.heap[largest], h.heap[idx]
		h.maxHeapify(largest)
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
#define dame { printf("No\n"); return 0;}
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)


template <typename T> class Dijkstra{
    vector<pair < T, int >>* edges;
    int* par;
    T* Distance;
    int size;

public:
    Dijkstra(int n){
        size = n;
        edges = new vector<pair<T , int> >[n];
        Distance = new T[n];
        par = new int[n];
    };

    T Get_Distance(int x){
        if(x < 0 or x>= size) return T(-1);
        else return Distance[x];
    };

    void add_edge(T dist, int s,int t);

    void Disp_Graph();

    void Get_Shortest(int s);



};


template<typename T> void Dijkstra<T>::add_edge(T dist, int s,int t){
    edges[s].push_back( mp(dist, t));
}

template<typename T> void Dijkstra<T>::Disp_Graph(){
    REP(i,size){
        REP(j,edges[i].size()){
            cout << edges[i][j].se << " " << edges[i][j].fi <<endl;
        }
        cout << endl;
    }
}


template<typename T> void Dijkstra<T>::Get_Shortest(int s){
    REP(i,size) Distance[i] = T(INF);
    reversed_priority_queue< pair<T, int > > Q;
    bool used[size];
    REP(i,size) used[i] = false;
    REP(i,size) par[i] = -1;
    int Q_size = 1;
    Distance[s] = 0;
    Q.push( mp(T(0),s ) );
    while(Q_size){
        pair < T, int > x = Q.top();
        Q.pop();
        Q_size --;
        if( used[x.se]) continue;
        used[x.se] = true;
        REP(i,edges[x.se].size()){
            pair < T, int > y = edges[x.se][i];
            if(  Distance[y.se] > Distance[x.se] + y.fi){
                Distance[y.se] = Distance[x.se] + y.fi;
                Q.push( mp ( Distance[y.se],y.se) );
                Q_size ++;
                par[y.se] = x.se;
            }
        }

    }

}











signed main(){
    int n,m,s;
    cin >> n;
    Dijkstra<int> D(n);
    int t1,d1;
    REP(i,n){
        int u,k;
        scanf("%lld%lld",&u,&k);
        REP(j,k){
            scanf("%lld%lld",&t1,&d1);
            D.add_edge(d1,u,t1);
        
        }
    }


    D.Get_Shortest(0);
    int tmp = 0;
    REP(i,n){
        printf("%lld %lld\n",i,D.Get_Distance(i));
    }
}

C++: #include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

static const int N = 10000;
static const int INF = 1000000;

struct Vertex {
    int id;
    bool in_S;
    int min_cost;
};

bool operator>(const Vertex &vertex1, const Vertex &vertex2)
{
    return vertex1.min_cost > vertex2.min_cost;
}


class SSSP {
private:
    vector<pair<int, int> > adj[N];
    Vertex vertex[N];
    int n;

public:
    SSSP()
    {
        cin >> n;
        int id;
        int degree;
        int v;
        int c;
        for (int i = 0; i < n; i++)
        {
            cin >> id;
            vertex[id].id = id;
            cin >> degree;
            for (int j = 0; j < degree; j++)
            {
                cin >> v >> c;
                adj[id].push_back(make_pair(v, c));
            }
        }
    }

    void dijkstra(int start)
    {
        priority_queue<Vertex, vector<Vertex>, greater<Vertex> > PQ;
        for (int i = 0; i < n; i++)
        {
            vertex[i].in_S = false;
            vertex[i].min_cost = INF;
        }
        vertex[start].min_cost = 0;

        PQ.push(vertex[start]);

        while (!PQ.empty())
        {
            int u = PQ.top().id;
            int cost = PQ.top().min_cost;
            PQ.pop();

            vertex[u].in_S = true;

            if (vertex[u].min_cost < cost)
                continue;

            for (int j = 0; j < adj[u].size(); j++)
            {
                int v = adj[u][j].first;
                if (!vertex[v].in_S)
                {
                    if (vertex[u].min_cost + adj[u][j].second < vertex[v].min_cost)
                    {
                        vertex[v].min_cost = vertex[u].min_cost + adj[u][j].second;
                        PQ.push(vertex[v]);
                    }
                }
            }
        }
    }

    void print()
    {
        for (int i = 0; i < n; i++)
            cout << i << " " << (vertex[i].min_cost == INF ? -1 : vertex[i].min_cost) << endl;
    }
};

int main()
{
    SSSP mst;
    mst.dijkstra(0);
    mst.print();
}