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 <cstdio>
#include <cstring>
#include <climits>
#include <queue>
#include <map>
using namespace std;

typedef map<int, int>::iterator mitr;

map<int, int> w[100];
int d[100];
char pos[100];

priority_queue<pair<int,int> > others;
pair<int,int> p;

void findPath(){
    p = others.top();
    others.pop();
    while(pos[p.second]){
        p = others.top();
        others.pop();
    }
    pos[p.second]=1;

    int tmpu = p.second;
    int tmpd = -p.first;

    for(mitr i=w[tmpu].begin();i!=w[tmpu].end();i++){
        if(tmpd + i->second < d[i->first]){
            d[i->first] = tmpd + i->second;
            others.push(make_pair(-d[i->first],i->first));
        }
    }
}

int main(){
    int i,j,u,k,n,v,c;

    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d %d",&u,&k);
        for(j=0;j<k;j++){
            scanf("%d %d",&v,&c);
            w[u][v] = c;
        }
    }

    memset(pos,0,sizeof(char)*100);
    for(i=0;i<n;i++)d[i]=INT_MAX;
    d[0] = 0;
    others.push(make_pair(0,0));
    for(i=0;i<n;i++)findPath();
    for(i=0;i<n;i++)printf("%d %d\n",i,d[i]);

    return 0;
}

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

using namespace std;

#define INF 10000000
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};

bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void shortestPath(const Graph &g, int s, vector<Weight> &dist, vector<int> &prev) {
  int n = g.size();
  dist.assign(n, INF); dist[s] = 0;
  prev.assign(n, -1);
  
  priority_queue<Edge> Q; // "e < f" <=> "e.weight > f.weight"
  for (Q.push(Edge(-2, s, 0)); !Q.empty(); ) {
    Edge e = Q.top(); Q.pop();
    if (prev[e.dst] != -1) continue;
    prev[e.dst] = e.src;
    FOR(f,g[e.dst]) {
      if (dist[f->dst] > e.weight+f->weight) {
        dist[f->dst] = e.weight+f->weight;
        Q.push(Edge(f->src, f->dst, e.weight+f->weight));
      }
    }
  }
}

int main(int argc, char* argv[]){
  int n;

  cin >> n;
  
  Graph graph;

  for(int i = 0; i < n; i++){
    int from, k;
    
    cin >> from >> k;

    Edges edges;    

    for(int j = 0; j < k; j++){
      int to, cost;
      cin >> to >> cost;
      
      Edge edge(from, to, cost);
      edges.push_back(edge);
    }
    // cout << edges.size();

    graph.push_back(edges);
  }

  vector<Weight> dist(n);
  vector<int> prev(n);
  
  shortestPath(graph, 0, dist, prev);

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

C++: #include <iostream>
#include <ios>
#include <vector>
#include <queue>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;

constexpr int INF = 1 << 30;

void read_graph(int n, vector<vector<pair<int, int>>> & Es){
    int u, k, v, c;
    while (n--){
        cin >> u >> k;
        while(k--){
            cin >> v >> c;
            Es[u].emplace_back(v, c);
        }
    }
}

void dijkstra(int start, const vector<vector<pair<int, int>>> & Es, vector<int> & dist){
    priority_queue<pair<int, int>, vector< pair<int, int> >, greater<pair<int, int> > > pq;
    pq.emplace(0, start);
    int d, u, v, c;
    while(!pq.empty()){
        tie(d, u) = pq.top();
        pq.pop();
        if (dist[u] < d) continue;
        dist[u] = d;
        for (auto p : Es[u]){
            tie(v, c) = p;
            if (d + c < dist[v]){
                dist[v] = d + c;
                pq.emplace(d + c, v);
            }
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    int n = 0;
    cin >> n;
    vector< vector< pair<int, int> > > Es(n);
    vector<int> dist(n, INF);
    
    read_graph(n, Es);
    dijkstra(0, Es, dist);
    
    for (int i = 0; i != n; ++i){
        cout << i << ' ' << dist[i] << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n + 1); ++i)
using namespace std;
using ll = long long;
const int INF = +100100100;
// typedef pair<int,int> P;
const int  WHITE = 0;
const int GRAY =1;
const int BLACK =2;
const int NIL = -1;
const int MAX = 10000;

// 配列のサイズを大きく取りすぎるとエラーが出ないが、実行できなくなる.
vector<int> color(MAX,WHITE), D(MAX,INF);
typedef pair<int,int> node;
vector<node> adj[MAX];
priority_queue<node> HQ;
int n;

void dijkstra(){
    int u = 0;
    D[u] = 0;
    HQ.push(make_pair(0,0));
    while(!HQ.empty()){
        node p = HQ.top();HQ.pop();
        int p_w = p.first;int p_i = p.second;
        if(color[p_i]==BLACK)continue;
        color[p_i]=BLACK;

        for(auto elm : adj[p_i]){
            int v_w = elm.first; int v_i = elm.second;
            if(color[v_i]==BLACK)continue;
            if(D[p_i]+v_w < D[v_i]){
                D[v_i]=D[p_i]+v_w;
                HQ.push(make_pair(D[v_i]*(-1),v_i));
            }
        }
    }
}

int main(){
    cin >> n;
    rep(i,n){
        int id, m;
        cin >> id>>m;
        rep(j,m){
            int opp;cin>>opp;
            int cost; cin >> cost;
            adj[i].push_back(make_pair(cost,opp));
        }
    }
    dijkstra();
    rep(i,n){
        cout<<i << " " << D[i]<<endl;
    }
    return 0;
}