Go: package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
)

type Item struct {
	value    int // The value of the item; arbitrary.
	priority int // The priority of the item in the queue.
	// The index is needed by update and is maintained by the heap.Interface methods.
	index int // The index of the item in the heap.
}
type PriorityQueue []*Item

func (pq PriorityQueue) Len() int { return len(pq) }
func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].priority < pq[j].priority
}
func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}
func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}
func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

type Q struct {
	pq *PriorityQueue
	ds map[int]int // It has always same value as pq. For random access.
}

func newQ() *Q {
	pq := new(PriorityQueue)
	heap.Init(pq)
	return &Q{
		pq: pq,
		ds: make(map[int]int),
	}
}
func (q *Q) pop() (u, d int) {
	item := heap.Pop(q.pq).(*Item)
	delete(q.ds, item.value)
	return item.value, item.priority
}
func (q *Q) get(u int) (int, bool) { // returns d
	d, ok := q.ds[u]
	return d, ok
}
func (q *Q) set(u, d int) {
	q.ds[u] = d
	for _, item := range *q.pq {
		if item.value != u {
			continue
		}

		item.priority = d
		heap.Fix(q.pq, item.index)
		return
	}
	heap.Push(q.pq, &Item{
		priority: d,
		value:    u,
	})
}
func (q *Q) len() int {
	return len(q.ds)
}

func main() {
	r := bufio.NewReader(os.Stdin)

	var n int
	fmt.Fscan(r, &n)
	cs := make([]map[int]int, n) // []v_i -> c_i
	for h := 0; h < n; h++ {
		var u, k int
		fmt.Fscan(r, &u, &k)
		m := make(map[int]int)
		for i := 0; i < k; i++ {
			var v, c int
			fmt.Fscan(r, &v, &c)
			m[v] = c
		}

		cs[u] = m
	}

	q := newQ()
	q.set(0, 0)
	visited := make(map[int]struct{})
	out := make([]int, n)

	for q.len() > 0 {
		u, d := q.pop()
		for uu, c := range cs[u] {
			// Consider the connection between u and uu.
			if _, ok := visited[uu]; ok {
				continue
			}
			dd := d + c
			if d, ok := q.get(uu); !ok || d > dd {
				q.set(uu, dd)
			}
		}

		out[u] = d
		visited[u] = struct{}{}
	}

	for u, d := range out {
		fmt.Println(u, d)
	}
}

C++: /*???????????????????????¢?????´???????????§?????????????°???¨??????????????????????????¢?´¢??????*/
/*????????????????????\????????¨???????????¨??§???????????????O((|E|+|V|)log|V|)?????§??????*/
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep0(i,i0,n) for(int i = i0;i<=n;i++)
using namespace std;
#define inf (1<<20)
#define MAX 100000

static const int White=0;
static const int Gray=1;
static const int Black=2;

int n;
vector<pair<int, int> > adj[MAX]; //??£??\?????????

void Dijkstra(){
    priority_queue<pair<int, int> > PQ;
    int color[MAX];
    int D[MAX];
    rep(i, n){
        D[i]=inf;
        color[i]=inf;
    }
    D[0]=0;
    PQ.push(make_pair(0, 0));
    color[0]=Gray;

    while(!PQ.empty()){
        pair<int, int> f=PQ.top(); PQ.pop();
        int u=f.second;
        color[u]=Black;

        //????°??????????????????????????????§???????????°????????????
        if(D[u] < f.first * (-1) ) continue;

        rep(j, adj[u].size()){
            int v =adj[u][j].first;
            if(color[v]==Black) continue;
            if(D[v] > D[u] + adj[u][j].second){
                D[v] = D[u] + adj[u][j].second;
                //????????????????????\????????§?????????????????????????????§????????????
                PQ.push(make_pair(D[v] * (-1), v));
                color[v]=Gray;
            }
        }
    }

    rep (i,n) cout << i << " " << ( D[i] == inf ? -1 : D[i]) << endl;
}

int main(void){
    int k,u,v,c;
    cin >> n;

    rep(i, n){
        cin >> u >>k;
        rep(j, k){
            cin >> v >> c;
            adj[u].push_back(make_pair(v, c));
        }
    }

    Dijkstra();

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1000 * 100000;

int main(void){
  int n;
  cin >> n;
  vector< vector<pair<int, int> > > g(n);
  for(int i=0; i < n; i++){
    int v; cin >> v;
    int k; cin >> k;
    for(int j=0; j < k; j++){
      int v0, c; cin >> v0 >> c;
      g[v].push_back(make_pair(v0, c));
    }
  }
  vector<ll> d(n, INF);
  vector<bool> used(n, false);
  priority_queue<pair <int, int> > pq;
  d[0] = 0;

  pq.push(make_pair(0, 0));

  while(!pq.empty()){
    pair<int, int> f = pq.top(); pq.pop();
    int u = f.second;
    used[u] = true;
    if(d[u] < f.first * (-1)) continue;

    for(int i=0; i < g[u].size(); i++){
      int v = g[u][i].first;
      if(used[v] == true) continue;
      if(d[v] > d[u] + g[u][i].second){
        d[v] = d[u] + g[u][i].second;
        pq.push(make_pair(d[v] * (-1), v));
      }
    }
  }
  for(int i=0; i < n; i++){
    cout << i << " " << d[i] << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#define MAX 100
#define INF (1<<30)

using namespace std;
enum state{
  BLACK,
  WHITE
};

int main(){
  vector<int> v[MAX];
  vector<int> c[MAX];
  state s[MAX];
  int d[MAX];
  int n; cin>>n;

  for(int i=0;i<n;i++){
    int u; cin>>u;
    int k; cin>>k;
    for(int j=0;j<k;j++){
      int tmp,tmp2; cin>>tmp>>tmp2;
      v[u].push_back(tmp);
      c[u].push_back(tmp2);
    }
  }

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

  vector<int> blacklist;
  blacklist.push_back(0);

  while(1){
    int& last = blacklist.back();
    for(int i = 0;i<v[last].size();i++){
      if(d[v[last][i]]>d[last]+c[last][i]){
        d[v[last][i]]=d[last]+c[last][i];
      }
    }

    int minv=-1;
    int mind=INF;
    for(int b:blacklist){
      for(int i=0;i<v[b].size();i++){
        if(s[v[b][i]]!=BLACK && d[v[b][i]]<mind){
          minv=v[b][i];
          mind=d[v[b][i]];
        }
      }
    }
    if(minv!=-1){
      s[minv]=BLACK;
      blacklist.push_back(minv);
    }else{
      break;
    }
  }

  for(int i=0;i<n;i++){
    printf("%d %d\n",i,d[i]);
  }
}