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 <queue>
using namespace std;

#define INFTY (1 << 30)

//???????????????
enum Color {
	WHITE,
	GRAY,
	BLACK,
};


//SSSP
void Dijkstra(vector<pair<int, int>> *v_w_m, int verNum) {

	//???????¨????
	priority_queue<pair<int, int>> pQ;
	int distance[10000];
	Color color[10000];
	int parent[10000];
	for (int i = 0; i < verNum; i++) {
		color[i] = WHITE;
		distance[i] = INFTY;
		parent[i] = -1;
	}
	distance[0] = 0;
	pQ.push(make_pair(0, 0));


	//SSSP??????
	while (!pQ.empty()) {

		//??°??¬????????????????????????????°?????????????????????¶
//		int min_cost = INFTY;
		int subScript;
		pair<int, int> wei_sub_map = pQ.top();
		pQ.pop();
		subScript = wei_sub_map.second;
		//for (int i = 0; i < verNum; i++) {
		//	if (color[i] != BLACK && distance[i] < min_cost) {
		//		min_cost = distance[i];
		//		subScript = i;
		//	}
		//}

		//?????????????????????
		color[subScript] = BLACK;

		//???????????????????????°??????????????????????????????????????????
		//?????????????????¨4169407B?????¨??????0.01sec????????????
		if (distance[subScript] < wei_sub_map.first * -1)
			continue;

		//??£??\?????°??¬??????
		for (int i = 0; i < v_w_m[subScript].size(); i++) {
			int outV = v_w_m[subScript][i].first;
			if (color[outV] == BLACK) continue;
			if (distance[outV] < distance[subScript] + v_w_m[subScript][i].second) continue;

			distance[outV] = distance[subScript] + v_w_m[subScript][i].second;
			parent[outV] = subScript;
			color[outV] = GRAY;
			pQ.push(make_pair(distance[outV] * -1, outV));
		}
	}

	//??????
	int weight_sum = 0;
	for (int i = 0; i < verNum; i++) {
		cout << i << " " << distance[i] << endl;
	}
}


int main() {

	int verNum;
//	int verValWeight[100][100];
	vector<pair<int, int>> v_w_m[10000];
	int parent[10000];

	//???????¨????
//	v_w_m = new vector<pair<int, int>>();
	cin >> verNum;
	//for (int i = 0; i < verNum; i++)
	//	for (int j = 0; j < verNum; j++)
	//		verValWeight[i][j] = INFTY;

	//??\?????????
	for (int i = 0; i < verNum; i++) {
		int verVal, outNum;
		cin >> verVal >> outNum;
		for (int j = 0; j < outNum; j++) {
			int outVerVal, weight;
			cin >> outVerVal >> weight;
//			v_w_m[verVal].push_back(make_pair(outVerVal, weight));
			v_w_m[verVal].push_back(make_pair(outVerVal, weight));
			//			verValWeight[i][outVerVal] = weight;
		}
	}

	//SSSP
	Dijkstra(v_w_m, verNum);

	return 0;
}

C++: #include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
const int INF = 1e9 ;
const int MAXN = 10100 ;
vector<pair<int, int> > edge[MAXN];
int n;
int d[MAXN], vis[MAXN];
priority_queue<pair<int, int> > q;
void Dij()
{
	for (int i = 0; i < n; ++i) d[i] = INF;
	d[0] = 0;
	q.push(make_pair(0, 0)) ;
	vis[0] = 1;
	while (! q.empty())
	{
		pair<int, int> cur = q.top();
		int u = cur.second;
		q.pop();
		vis[u] = 2;
		if (d[u] < cur.first * (-1)) continue ;
		for (int i = 0; i < edge[u].size(); ++i)
		{
			int to = edge[u][i].first;
			if (vis[to] == 2) continue ;
			if (d[to] > d[u] + edge[u][i].second)
			{
				d[to] = d[u] + edge[u][i].second;
				q.push(make_pair(d[to] * (-1), to));
				vis[to] = 1;
			}
		}
	}
}
int main()
{
	cin >> n;
	for (int i = 1; i <= n; ++i)
	{
		int u, k;
		cin >> u >> k;
		for (int j = 1; j <= k; ++j)
		{
			int v, c;
			cin >> v >> c;
			edge[u].push_back(make_pair(v, c));
		}
	}
	Dij();
	for (int i = 0; i < n; ++i)
		cout << i << " " << (d[i] == INF ? -1 : d[i]) << endl;
	return 0;
}

C++: #include <iostream>
#include <cstdio> 
using namespace std;
static const int INFTY = (1<<21);
int n, M[10000][10000];
int color[10000],d[10000],p[10000];

void dijkstra()
{
    for (int i = 0; i < n; i++)
    {
        d[i] = INFTY;
        p[i] = -1;
        color[i] = 0;
    } 
    
    d[0] = 0;

    while (true)
    { 
        int mincost = INFTY;
        int u = -1;
        for (int i = 0; i < n; i++)
        {
            if (color[i] != 2 && d[i] < mincost )
            { 
                mincost = d[i];
                u = i;
            }         
        } 
        if (mincost == INFTY) break;
        color[u] = 2;
        for (int v = 0; v < n; v++)
        {
            if (color[v] != 2 && d[u] + M[u][v] < d[v])
            { 
                d[v] = d[u] + M[u][v];
                p[v] = u;
                color[v] = 1;
            }  
        } 
    } 

}

int main()
{
    //freopen("in3.txt","r",stdin);
    int u,k,v,c;
    cin>>n;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            M[i][j] = INFTY; 
        }  
    } 
    for (int i = 0; i < n; i++)
    {
        cin>>u>>k;
        for (int j = 0; j < k; j++)
        {
            cin>>v>>c; 
            M[u][v] = c; 
        } 
    } 
    
    dijkstra();

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