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;
#define MAX_N 10000

typedef pair<long, long> P;

long N, d[MAX_N];
vector<P> edge[MAX_N];

void dijkstra(){
    bool seen[N];
    fill(seen, seen + N, false);
    priority_queue<P, vector<P>, greater<P> > todo;
    todo.push(P(0, 0));
    
    while(!todo.empty()){
        long dist = todo.top().first, v = todo.top().second;
        todo.pop();
        if(seen[v]) continue;
        d[v] = dist;
        seen[v] = true;
        for(long i = 0; i < edge[v].size(); i++){
            long w = edge[v][i].second, u = edge[v][i].first;
            if(d[v] + w < d[u]){
                d[u] = d[v] + w;
                todo.push(P(d[u], u));
            }
        }
    }
}

int main(){
    cin >> N;
    fill(d, d + MAX_N, LONG_MAX);
    for(long i = 0; i < N; i++){
        long v, k, u, c;
        cin >> v >> k;
        for(long j = 0; j < k; j++){
            cin >> u >> c;
            edge[v].push_back(P(u, c));
        }
    }
    
    dijkstra();
    
    for(long i = 0; i < N; i++)
        cout << i << " " << d[i] << endl;
    
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int INF;
int n;
vector<pair<int, int>> es[10000];

// sから各頂点への最短経路を求める
void dijkstra () {
  
  priority_queue<pair<int, int>> pq;
  int d[10000];

  // 0:未調査 1:調査中 2:調査完了
  int status[10000];

  for (int i = 0; i < n; i++) {
    d[i] = INF;
    status[i] = 0;
  }

  d[0] = 0;
  status[0] = 1;
  pq.push(make_pair(0,0));

  while (!pq.empty()) {

    pair<int, int> p = pq.top(); pq.pop();
    int u = p.second;
    status[u] = 2;

    // 最小値を取り出し、それが最短でなければ無視
    if (d[u] < p.first * (-1)) {
      continue;
    }
    
    for (int i = 0; i < es[u].size(); i++) {
      int v = es[u][i].first;
      if (status[v] == 2) {
        continue;
      }
      if (d[u] + es[u][i].second < d[v]) {
        d[v] = d[u] + es[u][i].second;
        // priority_queueはデフォルトで大きい順を優先するため-1を掛ける
        pq.push(make_pair(d[v] * (-1), v));
        status[v] = 1;
      }
    }
    
  }
  for (int i = 0; i < n; i++) {
    if (d[i] == INF) {
      cout << i << " -1" << endl;
    } else {
      cout << i << " " << d[i] << endl;
    } 
  }
}

int main() {
  
  cin >> n;

  INF = 20000000;

  // 入力を受け取る
  for (int i = 0; i < n; i++) {
    int u, k;
    cin >> u >> k;
    for (int j = 0; j < k; j++) {
      int v, c;
      cin >> v >> c;
      es[u].push_back(make_pair(v,c));
    }
  }

  // ダイクストラ法開始
  dijkstra();

  return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
static const int NMAX = 10000;
#define INF (1 << 30)

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> adj[NMAX];

  for (int i = 0; i < n; i++) {
    int id, nn;
    cin >> id >> nn;
    for (int j = 0; j < nn; j++) {
      int to, weight;
      cin >> to >> weight;
      // use negative weights for priority_queue
      adj[id].push_back(make_pair(-weight, to));
    }
  }

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

  priority_queue<pair<int, int>> distQ;

  // add node 0
  for (int i = 0; i < adj[0].size(); i++) {
    distQ.push(adj[0][i]);
    int weight = adj[0][i].first;
    int id = adj[0][i].second;
    dist[id] = weight;
  }
  visited[0] = true;

  while (!distQ.empty()) {
    // find nearest node
    int minnode = distQ.top().second;
    distQ.pop();

    // add node
    visited[minnode] = true;

    // update dist
    for (int i = 0; i < adj[minnode].size(); i++) {
      int weight = adj[minnode][i].first;
      int id = adj[minnode][i].second;

      if (visited[id] == false) {
        int newWeight = dist[minnode] + weight;
        if (-newWeight < -dist[id]) {
          distQ.push(make_pair(newWeight, id));
          dist[id] = newWeight;
        }
      }
    }
  }

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