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;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool prime(ll n) {
  if (n == 1) {
    return false;
  } else {
    for (ll i = 2; i <= (ll)pow(n, 0.5); i++) {
      if (n%i == 0) return false;
    }
  }
  return true;
}
ll RepeatSquaring(ll n, ll p, ll m) {
  if (p == 0) return 1;
  if (p%2 == 0) {
    ll t = RepeatSquaring(n, p/2, m);
    return (t*t)%m;
  }
  return (n*RepeatSquaring(n, p-1, m))%m;
}

vector <ll> color(10000, 0);
vector <ll> d(10000, INF);
priority_queue <pair <ll, ll>> pq;
vector <vector <pair <ll, ll>>> m(10000, vector <pair <ll, ll>> ());
ll n;

void dijkstra() {
  d.at(0) = 0;
  pq.push(make_pair(0, 0));
  while (!pq.empty()) {
    pair <ll, ll> u = pq.top();
    pq.pop();
    color.at(u.second) = 2;
    if (d.at(u.second) < u.first*(-1)) continue;
    rep(i, m.at(u.second).size()) {
      pair <ll, ll> v = m.at(u.second).at(i);
      if (color.at(v.first) != 2) {
        if (d.at(u.second)+v.second < d.at(v.first)) {
          d.at(v.first) = d.at(u.second)+v.second;
          color.at(v.first) = 1;
          pq.push(make_pair(d.at(v.first)*(-1), v.first));
        }
      }
    }
  }
}

int main() {
  cin >> n;
  rep(i, n) {
    ll u, k;
    cin >> u >> k;
    rep(j, k) {
      ll v, c;
      cin >> v >> c;
      m.at(u).push_back(make_pair(v, c));
    }
  }
  dijkstra();
  rep(i, n) {
    cout << i << ' ' << d.at(i) << endl;
  }
}

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[11111];
int d[11111];
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;
  }
}

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

using namespace std;

#define llong long long 
typedef struct data{
	vector<int> way;
	vector<int> waycost;
	int useway;
	int cost;
}data;

data d[101];

void solve(int N, int before){
	vector<int> nsolve;
	for(int i = 0; i < d[N].way.size(); i++){
		int nway = d[N].way[i];
		if(d[N].cost + d[N].waycost[i] < d[nway].cost){
			d[nway].cost = min(d[d[N].way[i]].cost, d[N].cost + d[N].waycost[i]);
			d[nway].useway = N;
			nsolve.push_back(nway);
		}
	}
	for(int i = 0; i < nsolve.size(); i++){
		solve(nsolve[i],0);
	}
}

int main(){
	int hownum;
	cin >> hownum;
	for(int i = 0; i < hownum; i++){
		int num;
		int howway;
		cin >> num >> howway;
		for(int j = 0; j < howway; j++){
			int w,c;
			cin >> w >> c;
			d[num].way.push_back(w);
			d[num].waycost.push_back(c);
		}

		if(num == 0) d[num].cost = 0;
		else d[num].cost = 10000000;
	}

	for(int i = 0; i < hownum; i++){
		solve(i, -1);
	}
	
	for(int i = 0; i < hownum; i++){
		cout << i << " " << d[i].cost << endl;
	}
	return 0;
}