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>	
#include <utility>	
#include <list>		
#define N 10000	
#define INF (1<<31-1);
using namespace std;

typedef pair<int,int> pii;	
vector<pii> adj[N];	
bool color[N];	
int dist[N];	
int n;	
priority_queue<pii> pq; 

int dijkstra(int k){	
	for(int i=0;i<n;i++){
		color[i]=false; 
		dist[i]=INF;	
	}
	color[k]=true; 
	dist[k]=0;	
	for(int i=0;i<adj[k].size();i++){
		pq.push(adj[k][i]); 
	}
	while(!pq.empty()){	
		pii temp=pq.top();pq.pop();	
		temp.first=-temp.first;	
		if(color[temp.second])continue;	
		color[temp.second]=true; 
		dist[temp.second]=temp.first;	
		for(int i=0;i<adj[temp.second].size();i++){
			if(!color[adj[temp.second][i].second])pq.push(make_pair(-dist[temp.second]+adj[temp.second][i].first,adj[temp.second][i].second));
		}
	}

	for(int i=0;i<n;i++) cout<<i<<" "<<dist[i]<<endl;
	return 0;
}
int main(void){
	int v,c;	
	int u,k;	
	cin>>n; 
	for(int i=0;i<n;i++){ 
		cin>>u>>k;	
		for(int j=0;j<k;j++){
			cin>>v>>c;	
			adj[u].push_back(make_pair(-c,v));	
		}
	}
	dijkstra(0);	
	return 0;
}

C++: # include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)
# pragma warning(disable:4996)

int V, E;
struct edge { LL to, cost; };
int start;
LL d[100100]; //距離
vector<edge> vec[1010];

void dijkstra() {
	for (int i = 0; i < 100100; i++)d[i] = HINF<LL>();
	priority_queue<pii, std::vector<pii>, std::greater<pii>> pq;
	d[start] = 0;
	pq.push(make_pair(d[start], start));//cost,to
	while (!pq.empty()) {
		pii p = pq.top();
		pq.pop();
		int i = p.second;
		if (d[i] < p.first)continue;
		for (int k = 0; k < vec[i].size(); k++) {
			edge e = vec[i][k];
			if (d[e.to] <= d[i] + e.cost)continue;
			d[e.to] = d[i] + e.cost;
			pq.push(make_pair(d[e.to], e.to));
		}
	}
}

int main() {
	cin >> V;
	REP(i, V) {
		int u;
		cin >> u;
		int num;
		cin >> num;
		REP(j, num) {
			int v, c;
			cin >> v >> c;
			vec[u].emplace_back(edge{ v,c });
		}
	}
	dijkstra();
	REP(i, V) {
		cout << i << " " << d[i] << endl;
	}
}

C++: 
#include<bits/stdc++.h>

using namespace std;

const int maxn=1e4+5;
const int inf=(1<<20);
const int white=0;
const int gray=1;
const int black=2;

int n;
vector<pair<int,int> >adj[maxn];

void dijkstra()
{
    priority_queue<pair<int,int> >q;
    int book[maxn],d[maxn];
    for(int i=0;i<n;i++){
        d[i]=inf;
        book[i]=0;
    }
    d[0]=0;
    q.push(make_pair(0,0));
    while(!q.empty()){
        pair<int,int>f=q.top();
        q.pop();
        int u=f.second;
        book[u]=1;
        if(d[u]<f.first*(-1)){
            continue;
        }
        for(int j=0;j<adj[u].size();j++){
            int v=adj[u][j].first;
            if(book[v]==1){
                continue;
            }
            if(d[v]>d[u]+adj[u][j].second){
                d[v]=d[u]+adj[u][j].second;
                q.push(make_pair(d[v]*(-1),v));
            }
        }
    }
    for(int i=0;i<n;i++){
        cout<<i<<" "<<(d[i]==inf?-1:d[i])<<endl;
    }
}

int main()
{
    scanf("%d",&n);
    int u,k,v,c;
    for(int i=0;i<n;i++){
        cin>>u>>k;
        for(int i=0;i<k;i++){
            cin>>v>>c;
            adj[u].push_back(make_pair(v,c));
        }
    }
    dijkstra();
    return 0;
}