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++: 
#include<iostream>

using namespace std;


static const int MAX = 100;
static const int inf = (1 << 21);
static const int white = 0;
static const int gray = 1;
static const int black = 2;

int n, m[MAX][MAX];
int sht[MAX];


void dijkstra() {

	int u, minv;
	int d[MAX], p[MAX], color[MAX];

	for (int i = 0; i < n; i++)
	{
		sht[i] = d[i] = inf;
		p[i] = -1;
		color[i] = white;
	}

	d[0] = 0;
	color[0] = gray;

	while (1)
	{
		minv = inf;
		u = -1;

		for (int i = 0; i < n; i++) {
			if (minv > d[i] && color[i] != black) {
				u = i;
				minv = d[i];
			}
		}

		if (u == -1) break;
		color[u] = black;

		for (int v = 0; v < n; v++) {
			if (color[v] != black && m[u][v] != inf) {
				if (d[v] > d[u] + m[u][v]) {
					d[v] = d[u] + m[u][v];
					color[v] = gray;
				}
			}
		}
	}

	for (int i = 0; i < n; i++) {
		cout << i << " " << (d[i] == inf ? -1 : d[i]) << endl;

	}
}


int main() {


	cin >> n;

	for (int i = 0;i < n;i++) {
		for (int k = 0; k < n; k++)
		{
			m[i][k] = inf;
		}
	}

	int nm, c, u, v;
	for (int i = 0;i < n;i++) {
		cin >> u >> nm;
		for (int k = 0; k < nm; k++)
		{
			cin >> v >> c;
			m[u][v] = c;
		}
	}

	dijkstra();

	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#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;
    for(int b:blacklist){
      for(int i=0;i<v[b].size();i++){
        if(s[v[b][i]]!=BLACK && d[v[b][i]]<d[minv]){
          minv=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]);
  }
}

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

#define rep(i, n) REP(i, 0, n)
#define REP(i,k,n) for(int i = k; i < n; i++)
#define mmax(start, end) *max_element(start, end)
#define mmin(start, end) *min_element(start, end)
#define argmax max_element
#define argmin min_element
#define push push_back
#define pop pop_back
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef string str;

int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

template<class T = ll> T in() {
    T _in;
    cin >> _in;
    return _in;
}

#define EMAX 10000000

int cost[101][101];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n=in();
    ll d[101];

    rep(i, n) {
        rep(j, n) {
            cost[i][j] = EMAX;
        }
        d[i] = EMAX;
    }

    rep(i, n) {
        int u=in<int>(), k=in<int>();
        rep(j, k) {
            int v=in<int>(), c=in<int>();
            cost[u][v] = c;
        }
    }

    // ノード0からの距離を調べる
    d[0] = 0;
    bool flag = true;
    while(flag) {
        flag=false;
        // 移動する方法のある全ノードからの，次のノードへの移動コストを考える
        rep(i, n) {
            if(d[i] != EMAX) {
                rep(j, n) {
                    if(i == j)
                        continue;
                    int next_c = d[i] + cost[i][j];

                    // 更新できる場合更新
                    if(d[j] > next_c) {
                        d[j] = next_c;
                        flag=true;
                    }
                }
            }
        }
    }

    rep(i, n) {
        cout << i << " " << d[i] << endl;
        // rep(j, n) {
        //     cout << cost[i][j] << " ";
        // }
        // cout << endl;
    }
    
    return 0;
}

C++: #include <iostream>
using namespace std;
static const int MAX=100;
static const int INF=1<<21;
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;

int n,A[MAX][MAX];

void dijkstra(){
  int color[MAX],mincost,k,p[MAX],d[MAX];

  for(int i=0;i>n;i++){
    color[i]=WHITE;
    d[i]=INF;
  }
  d[0]=0;
  p[0]=-1;
  color[0]=GRAY;

  while(1){
    mincost=INF;
    for(int i=0;i<n;i++){
      if(color[i]!=BLACK && d[i]<mincost){
	mincost=d[i];
	k=i;
      }
    }
    if(mincost==INF) break;
    color[k]=BLACK;

    for(int i=0;i<n;i++){
      if(color[i]!=BLACK && A[k][i]!=INF){
	if(d[k]+A[k][i]<d[i]){
	  d[i]=d[k]+A[k][i];
	  p[i]=k;
	  color[i]=GRAY;
	}
      }
    }
  }
  for(int i=0;i<n;i++){
    cout<<i<<" "<<(d[i]==INF ? -1:d[i])<<endl;
  }
}


int main(){
  int i,j,k,c,u,v;
  cin>>n;
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      A[i][j]=INF;
    }
  }
  for(i=0;i<n;i++){
    cin>>u>>k;
    for(j=0;j<k;j++){
      cin>>v>>c;
      A[u][v]=c;
    }
  }

  dijkstra();
}