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 <iostream>
#include <vector>
#include <queue>
#include <functional>
#include <utility>
using namespace std;

const int MAX = 10000;
const int INF = 1 << 29;

int n;
vector<pair<int, int>> cost[MAX];

void solve()
{
	int ans[MAX];
	bool visited[MAX];
	priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> PQ;

	for (int i = 0; i < n; i++) {
		ans[i] = INF;
		visited[i] = false;
	}

	ans[0] = 0;

	PQ.push(make_pair(0, 0));

	while (PQ.empty() == false) {
		pair<int, int> p = PQ.top();
		PQ.pop();

		visited[p.second] = true;

		if (ans[p.second] < p.first) {
			continue;
		}

		for (unsigned int i = 0; i < cost[p.second].size(); i++) {
			int v = cost[p.second][i].second;

			if (visited[v] == true) {
				continue;
			}

			if (ans[v] > ans[p.second] + cost[p.second][i].first) {
				ans[v] = ans[p.second] + cost[p.second][i].first;
				PQ.push(make_pair(ans[v], v));
			}
		}
	}


	for (int i = 0; i < n; i++) {
		cout << i << " " << ans[i] << endl;
	}
}

int main()
{
	cin >> n;

	for (int i = 0; i < n; i++) {
		int num;
		cin >> num >> num;

		for (int j = 0; j < num; j++) {
			int v, c;
			cin >> v >> c;
			cost[i].push_back(make_pair(c, v));//(?????¢,?????????
		}
	}


	solve();

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define INT_MAX 10000000
#define MAX 10001

int d[MAX];
int n;
priority_queue<pair<int,int> > q;
vector<pair<int,int> > adj[MAX];
vector<int> s;

int check(int point){
    if(find(s.begin(), s.end(), point) != s.end()){
        //printf("%d in q\n",point);
        return 1;
    }
    else{
        //printf("%d not in q\n",point);
        return 0;
    }
}

void dijk(){
    q.push(make_pair(0,0));
    int new_node, v;
    while(s.size()!=n){
        // get smallest value
        pair<int,int> pa = q.top();
        new_node = pa.second;
        if(check(new_node)==0){
            s.push_back(new_node);
        }

        q.pop();

        for(int i=0;i<adj[new_node].size();++i){
            v = adj[new_node][i].first;
            if(d[new_node]+adj[new_node][i].second<d[v]){
                d[v] = d[new_node]+adj[new_node][i].second;
                q.push(make_pair(d[v]*(-1),v));
            }
        }
    }
}

int main(){
    int id, pair_n, source, dis;
    int value;
    //FILE *fp=fopen("In3.txt","r");
    scanf("%d",&n);
    for(int i=0;i<n;++i){
        scanf("%d %d",&id, &pair_n);
        //cin >> id >> pair_n;
        for(int j=0;j<pair_n;++j){
            scanf("%d %d",&source, &dis);
            //cin >> source >> dis;
            adj[id].push_back(make_pair(source,dis));
        }
    }
    d[0] = 0;
    for(int i=1;i<n;++i){
        d[i] = INT_MAX;
    }
    dijk();
    for(int i=0;i<n;++i){
        printf("%d %d\n",i,d[i]);
    }

    return 0;
}

C++: #include<iostream>
using namespace std;
#include<queue>
#include<vector>
#include<string>
#include<string.h>
#include<algorithm>
bool b[2003];

#define REP(i, a) for(int i=0;i<a;i++)
	int N=(1<<20);
int main()
{
	pair<int,int> f;
	vector < pair<int,int> > A[10001];
	priority_queue < pair < int,int > > PQ;
	int min,b,a,k,m,n ,e,p[101],d[101],u,v; //u ?????????v????????¨
	bool color[10001];

	cin>>n;
	REP(i, n) {
		cin>>u>>k;
		REP(i, k) {
			cin>>a>>b;
			if(b==-1) b=N;
			A[u].push_back(make_pair(a,b));
		}
		color[i]=0;
		d[i]=N;
	}
	a=0;
	d[0]=0;
	PQ.push(make_pair(0,0));
	while(!PQ.empty()){
		f=PQ.top();
		PQ.pop();
		u=f.second;
		color[u]=1;
		REP(i,A[u].size()){
			v=A[u][i].first;
			if(color[v]==1){
			continue;
			}
				if(d[v]>A[u][i].second+d[u]){
					d[v]=A[u][i].second+d[u];
					PQ.push(make_pair(d[v]*-1,v));
				}
		}
	}
	REP(i,n){
		cout<<i<<" "<<(d[i] == N ? -1 : d[i])<<endl;
	
	}
	return 0;
}

C++: #include<stdio.h>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<queue>
#include<functional>
using namespace std;
int main(){
	int s;
	int g;
	int a;
	int b;
	int f;
	int t;
	vector<int> n[10000];
	int nn[10000];
	vector<int> x[10000];
	priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>y;
	vector<pair<int, int>>::iterator yy;
	int z;
	int d[10000];
	int e;
	int c[10000];
	int p;
	int q;
	int zz;
	pair<int, int>pai;
	for (int i = 0; i < 10000; i++){
		d[i] = 1000000009;
		c[i] = 0;
	}
	scanf("%d", &a);
	for (int i = 0; i < a; i++){
		scanf("%d %d", &s, &b);
		for (int j = 0; j < b; j++){
			scanf("%d %d",&t, &e);
			if (s > t){
				n[s].push_back(t);
				n[t].push_back(s);
				nn[s]++;
				nn[t]++;
				x[s].push_back(e);
				x[t].push_back(e);
			}
		}
	}
	d[0] = 0;
	y.push(std::make_pair(d[0], 0));
	for (int i = 0; y.empty() == 0; i++){
		zz = 0;
		for (int j = 0; y.empty() == 0 && zz == 0; j++){
			pai = y.top();
			z = pai.second;
			if (c[z] == 0)zz++;
			else y.pop();
		}
		if (zz == 0)break;
		c[z] = 1;
		for (int j = 0; j < nn[z]; j++){
			if (d[z] + x[z][j] < d[n[z][j]])
			{
				d[n[z][j]] = d[z] + x[z][j];
				y.push(std::make_pair(d[n[z][j]], n[z][j]));
			}
		}
		y.pop();
	}
	for (int i = 0; i < a; i++){
		printf("%d %d\n",i, d[i]);
	}

	return 0;
}