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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define MAX 10000000000

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

  int n; cin >> n;

  vector< vector< P > > f(n);
  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;
      f[u].push_back(make_pair(v, c));
    }
  }

  priority_queue< P, vector<P>, greater<P> > que;
  vector<ll> d(n, MAX);
  d[0] = 0;
  que.push(make_pair(0, 0));

  while(!que.empty()){
    P q = que.top(); que.pop();
    if(q.first > d[q.second]) continue;
    
    for(int i = 0; i < f[q.second].size(); i++){
      if(d[ f[q.second][i].first ] > d[q.second] + f[q.second][i].second){
        d[ f[q.second][i].first ] = d[q.second] + f[q.second][i].second;
        que.push(make_pair(d[ f[q.second][i].first ], f[q.second][i].first));
      }
    }
  }

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

  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

const long long INFF = 1e18;

const int MAX_N = 11000;
using TYPE = long long; // ?????¢???????????\??????
vector<pair<int, TYPE> > G[MAX_N];

vector<TYPE> dijkstra(int start){
	vector<TYPE> dist(MAX_N, INFF);
	dist[start] = 0;//dist[i] :=???start->i?????§??????????????¢
	priority_queue<pair<TYPE, int>, vector<pair<TYPE, int> >, greater<pair<TYPE, int> > >  que;
	que.push(make_pair(0, start));
	while(!que.empty()){
		TYPE cost; int u;//????????§???????????£????????? ?????¨?????????
		cost = que.top().first, u = que.top().second;
		que.pop();
		if(dist[u] < cost) continue;
		for (auto tmp : G[u]){
			int v = tmp.first; TYPE time = tmp.second;//??£??\???????????? ?????????????????§????????????
			if(dist[v] > dist[u] + time){//u->v
				// if(dist[v] != INFF) printf("%f %fa\n", dist[v], dist[u] + time);
				dist[v] = dist[u] + time;
				que.push(make_pair(dist[v], v));
			}
		}
	}
	return dist;
}


int main(void) {
	int n; cin >> n;
	rep(q, n) {
		int u, k; cin >> u >> k;
		vector<int> v(k); vector<long long> c(k);
		rep(i, k) cin >> v[i] >> c[i];
		rep(i, k) G[u].push_back(make_pair(v[i], c[i]));
	}
	auto dist = dijkstra(0);
	rep(i, n) printf("%d %d\n", i, dist[i]);
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <queue>
#include <limits>
using namespace std;

typedef pair<int,int> vec;

vector<vec> adj[10000];
int d[10000];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=0; i<n; i++) d[i]=numeric_limits<int>::max();
    for(int i=0; i<n; i++) {
        int u,k;
        cin>>u>>k;
        adj[u].reserve(k);
        for(int j=0; j<k; j++) {
            int v,c;
            cin>>v>>c;
            adj[u].push_back(vec(v,c));
        }
    }
    priority_queue<vec, vector<vec>, greater<vec> >q;
    q.push(vec(0,0));
    while(!q.empty()) {
        vec e=q.top();
        q.pop();
        int id=e.first;
        int cost=e.second;
        if(d[id]<cost) continue;
        for(int i=0, an=adj[i].size(); i<an; i++) {
            int adj_id=adj[id][i].first;
            int adj_cost=adj[id][i].second;
            if(d[adj_id] <= adj_cost) continue;
            d[adj_id]=adj_cost;
            q.push(vec(adj_id, adj_cost));
        }
    }
    for(int i=0; i<n; i++) cout<<i<<' '<<d[i]<<'\n';
    return 0;
}

C++: #include <vector>
#include <iostream>
#include <limits>
#include <queue>
#include <utility>

using namespace std;


struct edge {
    int src;
    int dst;
    int weight;

    edge(int src, int dst, int w) : src(src), dst(dst), weight(w) {}
};

bool operator < (const edge &a, const edge &b) {
  return a.weight > b.weight;
}


int main() {
    int n;
    cin >> n;

    vector<vector<pair<int, int>>> G(n);
    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;
            G[u].emplace_back(v, c);
        }
    }

    // Dijkstra's algorithm (with pritority queue)
    vector<int> d(n, -1);
    vector<bool> visited(n, false);
    priority_queue<edge> Q;

    Q.emplace(-1, 0, 0);
    while (!Q.empty()) {
        auto e = Q.top(); Q.pop();
        if (visited[e.dst])
            continue;
        d[e.dst] = e.weight;
        visited[e.dst] = true;

        for (auto& x : G[e.dst]) {
            if (visited[x.first])
                continue;
            int w = x.second + d[e.dst];
            Q.emplace(e.dst, x.first, w);
        }
    }

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

    return 0;
}