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;

const int MAX = 100;
const int INFINITY = 2 << 21;
int n;
int G[MAX][MAX];
int distances[MAX];
int states[MAX];

void dijkstra() {
  int id = 0;
  distances[id] = 0;

  while (1) {
    int min = INFINITY;

    for (int i = 0; i < n; i++) {
      if (states[i] == 0 && distances[i] < min) {
        min = distances[i];
        id = i;
      }
    }

    if (min == INFINITY) break;

    for (int i = 0; i < n; i++) {
      if (states[i] != 0 || G[id][i] == -1) continue;
      if (G[id][i] < distances[i]) {
        distances[i] = distances[id]+ G[id][i];
      }
    }

    states[id] = 1;
  }

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

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

  cin >> n;

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) G[i][j] = INFINITY;
  }

  int u, k, v, c;
  for (int i = 0; i < n; i++) {
    distances[i] = INFINITY;
    states[i] = 0;
    cin >> u >> k;
    for (int j = 0; j < k; j++) {
      cin >> v >> c;
      G[i][v] = c;
    }
  }

  dijkstra();

  return 0;
}

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

using namespace std;

#define MAX_V 10000
#define INF 1e9

struct edge{ int to,cost; };
typedef pair<int,int> P;

int V;
vector<edge> G[MAX_V];
int dist[MAX_V];

void dijkstra(){
  priority_queue<P, vector<P>, greater<P> > Q;
  fill(dist,dist+V,INF);
  dist[0] = 0;
  Q.push(P(0,0));

  while(!Q.empty()){
    P p = Q.top(); Q.pop();
    int v = p.second;

    if(dist[v] < p.first){
      continue;
    }

    for(int i = 0 ; i < (int)G[v].size() ; i++){
      edge e = G[v][i];
      
      if(dist[e.to] > dist[v] + e.cost){
	dist[e.to] = dist[v] + e.cost;
	Q.push(P(dist[e.to],e.to));
      }
    }

  }
}

int main(){
  cin >> V;
 
  for(int i = 0 ; i < V ; i++){
    int u,k;

    cin >> u >> k;
    for(int j = 0 ; j < k ; j++){
      int v,c;

      cin >> v >> c;

      edge e = {v,c};
      G[u].push_back(e);
    }
  }

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

  return 0;
}

C++: #include<iostream>
#include<cstdio>
#define INF 1<<30
#define FinishFunction return 0
#define MAX 1000000
using namespace std;
     
struct edge {
  int from,to,cost,k;
};
   
edge es[MAX];
   
int main(){
  int n,u,k,E,c,v;
  E = 0;
  scanf("%d",&n);
   
  for(int i=0;i<n;i++){
    scanf("%d %d",&u,&k);
      
    for(int j=0;j<k;j++){
      scanf("%d %d",&v,&c);
      es[E].from = u;
      es[E].to = v;
      es[E++].cost = c;
    }
  }
   
  // Ika berumanfo-do  
  int d[MAX];
  for(int i=0;i<n;i++)d[i] = INF;
  d[0] = 0;
  while(true){
    bool update = false;
    for(int i=0;i<E;i++){
      edge e = es[i];
      if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
    d[e.to] = d[e.from] + e.cost;
    update = true;
      }
    }
    if(!update)break;
  }
  for(int i=0;i<n;i++)cout << i << " " << d[i] << endl;
  FinishFunction;// return 0
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
using namespace std;

const int NIL = -1;
const int MAX = 1 << 21;

int color[10001], d[10001];

struct Node {
	int node, weight;
};
vector<Node>M[10001];

struct cmp {
	bool operator () (Node a, Node b)
	{
		return a.weight > b.weight;
	}
};

int next(int u) {
	for (int i = 0; i < M[u].size(); i++) {
		if (color[M[u][i].node] == 0) {
			color[M[u][i].node] = 1;
			return i;
		}
	}
	return -1;
}

int main(void)
{
	int n, u, k, v, c;
	priority_queue<Node, vector<Node>, cmp>PQ;
	Node s;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			cin >> v >> c;
			s.node = v;
			s.weight = c;
			M[u].push_back(s);
		}
	}
	for (int i = 0; i < n; i++) {
		color[i] = 0;
		d[i] = MAX;
	}
	d[0] = 0;
	s.node = s.weight = 0;
	PQ.push(s);
	while (!PQ.empty()) {
		Node u = PQ.top();
		PQ.pop();
		color[u.node] = 2;
		for (int i = 0; i < n; i++) {
			if (color[i] != 2)
				color[i] = 0;
		}
		if (d[u.node] < u.weight)
			continue;
		while ((v = next(u.node)) != NIL) {
			int tmp = M[u.node][v].node;
			if (color[tmp] != 2) {
				if (d[u.node] + M[u.node][v].weight < d[tmp]) {
					d[tmp] = M[u.node][v].weight + d[u.node];
					s.node = tmp;
					s.weight = d[tmp];
					PQ.push(s);
				}
			}
		}
	}
	for (int i = 0; i < n; i++) {
		cout << i << " " << d[i] << endl;
	}
	return 0;
}

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

typedef long long ll;

struct Edge {
    ll t,w;
};

struct State {
    ll v;
    ll score;
    bool operator < (const State& tgt) const {
	return score > tgt.score;
    }
};

vector<ll> dijkstra(vector<vector<Edge>>& G, const int start) {
    const ll V = G.size();

    vector<ll>res(V,INT_MAX);
    priority_queue<State> q;
    q.push( State{0,0} );
    while( q.size() ) {
	State s = q.top(); q.pop();
	if( res[s.v] != INT_MAX ) continue;
	res[s.v] = s.score;
	for(auto& e : G[s.v]) {
	    if( res[e.t] != INT_MAX ) continue;
	    q.push( State{e.t, s.score + e.w} );
	}
    }
    return res;
}


int main () {

    ll V; cin >> V;
    vector<vector<Edge>> G(V);
    for(int i=0; i<V; i++) {
	ll u,k; cin >> u >> k;
	for(int j=0; j<k; j++) {
	    ll v,w; cin >> v >> w;
	    G[i].push_back( Edge{v,w} );
	}
    }
    vector<ll> res = dijkstra(G,0);
    for(int i=0; i<V; i++) {
	cout << i << " " << res[i] << endl;
    }    
    return 0;
}