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>
using namespace std;
#define max 10000
#define infty 1<<21

int n;
int d[max];
int color[max];
vector<vector<int> > v(max);

void soya() {
	d[0] = 0;
	while (1) {
		int x = infty;
		for (int i = 0; i < n; i++) {
			if (x != infty) {
				if (d[i] < d[x] && color[i] != 2) {
					x = i;
				}
			}
			else {
				if (d[i] < x && color[i] != 2) {
					x = i;
				}
			}
		}

		if (x == infty) break;
		else {
			color[x] = 2;
			for (int i = 0; i < v[x].size() / 2; i++) {
				if (d[x] +v[x][(2 * i) + 1] < d[v[x][2 * i]]) {
					d[v[x][2 * i]] = d[x] + v[x][(2 * i) + 1];
				}
			}
		}
	}
}

int main() {
	for (int i = 0; i < max; i++) {
		color[i] = 0;
		d[i] = infty;
	}

	cin >> n;
	for (int i = 0; i < n; i++) {
		int id;
		int k;
		cin >> id >> k;
		for (int j = 0; j < k; j++) {
			int num1;
			int kyori;
			cin >> num1 >> kyori;
			v[id].push_back(num1);
			v[id].push_back(kyori);
		}
	}

	soya();

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

	return 0;
}

C++: #include<iostream>
#include<cstdlib>
#include<cstdio>
#define N 10001
#define INF 1000000009
using namespace std;

struct Heap{
  int key,cost;
};

struct node{
  int key,cost;
  node *prev,*next;
};

node *nil[N];
int n,d[N];
Heap A[N];

void init(){
  for(int i=0;i<n;i++){
  nil[i] = (node *)malloc(sizeof(node));
  nil[i]->next =nil[i];
  nil[i]->prev=nil[i];
  }
}

void insert(int i,int key,int cost){
  node *x= (node *)malloc(sizeof(node));
  x->key = key,x->cost=cost;
  x->next = nil[i]->next;
  nil[i]->next->prev = x;
  nil[i]->next = x;
  x->prev = nil[i];
}

int size;
void increase(int i,int key,int cost){
  Heap tmp;
  A[i].key=key,A[i].cost=cost;
  while(i>1 && A[i/2].cost > A[i].cost)tmp=A[i],A[i]=A[i/2],A[i/2]=tmp,i=i/2;
}

void insert(int key,int cost){
  size++,A[size].key=INF,A[size].cost=INF;
  increase(size,key,cost);
  }

void minHeapify(int i){
  int l,r,min;
  Heap tmp;
 l=i*2;
  r=i*2+1;
  if(l<=size && A[l].cost<A[i].cost)min=l;
  else min=i;
  if(r<=size && A[r].cost<A[min].cost)min=r;
  if(min!=i){tmp=A[i],A[i]=A[min],A[min]=tmp; minHeapify(min);}
}


Heap extractMin(){
  Heap min;
  min=A[1],A[1]=A[size],size--,minHeapify(1);
  return min;
}

void dijkstra(int s){
  Heap u;
  int used[N];
  for(int i=0;i<n;i++) used[i]=0,d[i]=INF;
  d[s]=0;
  while(size>=1){
    u=extractMin();
    used[u.key]=2;
    if(d[u.key] <u.cost)continue;
    node *v=nil[u.key]->next;
    while(v!=nil[u.key]){
      if(used[v->key]!=2)
	if(d[u.key]+v->cost<d[v->key])
	  d[v->key]=d[u.key]+v->cost,used[v->key]=1,insert(v->key,d[v->key]);
      v=v->next;
  }
}
}

int main(){
  cin>>n;
  init();
  int u,k,v,c;
  size=n;
  for(int i=0;i<n;i++){
    cin>>u>>k;
    for(int j=0;j<k;j++){
      cin>>v>>c;
      insert(u,v,c);
    }
  }
  dijkstra(0);
  for(int i=0;i<n;i++)cout<<i<<" "<<d[i]<<endl;
  
  return 0;
}

C++: #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
const int inf = 1e9;
// ダイクストラO(elogv)
struct edge{
  int to, cost;
  edge(int t, int c) {
    to = t, cost = c;
  }
};
typedef pair<int, int> P;
int N;
vector<edge> G[111];
int d[111];
void dijkstra(int s){
  priority_queue<P, vector<P>, greater<P> >que;
  FOR(i,1,N+1) d[i] = inf;
  d[s] = 0;
  que.push(P(0, s));
  while(!que.empty()){
    P p = que.top(); que.pop();
    int v = p.second;
    if(d[v] < p.first) continue;
    for(auto &e : G[v]){
      if(d[e.to] > d[v] + e.cost){
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin>>N;
  FOR(i,0,N){
    int u, k;
    cin >> u >> k;
    FOR(j,0,k){
      int v, c;
      cin >> v >> c;
      G[u].push_back(edge(v, c));
    }
  }
  dijkstra(0);
  FOR(i,0,N){
    cout << i << " " << d[i] << endl;
  }
}