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++: /*
 * Input
 * An edge-weighted graph G (V, E) and the source r.
 *
 * |V| |E| r
 * s0 t0 d0
 * s1 t1 d1
 * :
 * s|E|−1 t|E|−1 d|E|−1
 * |V| is the number of vertices and |E| is the number of edges in G. The graph
 * vertices are named with the numbers 0, 1,..., |V|−1 respectively. r is the
 * source of the graph.
 *
 * si and ti represent source and target vertices of i-th edge (directed) and di
 * represents the cost of the i-th edge.
 *
 * Output
 * c0
 * c1
 * :
 * c|V|−1
 * The output consists of |V| lines. Print the cost of the shortest path from
 * the source r to each vertex 0, 1, ... |V|−1 in order. If there is no path
 * from the source to a vertex, print INF.
 *
 * Constraints
 * 1 ≤ |V| ≤ 100000
 * 0 ≤ di ≤ 10000
 * 0 ≤ |E| ≤ 500000
 * There are no parallel edges
 * There are no self-loops
 */

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;

int main() {
  int n, m, source = 0;
  cin >> n; // >> m >> source;
  vector<map<int, int>> adj(100000);

  vector<int> d(100000, 1000000001);
  bool visited[100000];
  int n_visited = 0;

  for (int u, k; cin >> u >> k;) {
    for (int i = 0, v, len; i < k; ++i) {
      cin >> v >> len;
      adj[u][v] = len;
    }
  }

  auto cmp = [&](int s, int t) { return d[s] > d[t]; };
  priority_queue<int, vector<int>, decltype(cmp)> q(cmp);

  d[source] = 0;
  q.push(source);
  while (!q.empty() and n_visited < n) {
    auto u = q.top();
    q.pop();
    if (visited[u])
      continue;
    ++n_visited;
    visited[u] = true;
    for (auto &kv : adj[u]) {
      d[kv.first] = min(d[kv.first], d[u] + kv.second);
      q.push(kv.first);
    }
  }

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

C++: #include<stdio.h>
#include<string.h>
long long arr[205][205];
long long min(long long a,long long b){
	return a>b?b:a;
}
int main() {
    int n,m;
    while(scanf("%d",&n)!=EOF){
    	long long x,y,c,d;
    	for(int i=0;i<205;i++){
    		for(int j=0;j<205;j++){
    		 arr[i][j]=10000000;	
			}
		}
    	for(int j=0;j<n;j++){
    	scanf("%lld %lld",&x,&y);
    	for(int h=0;h<y;h++){
    		scanf("%lld %lld",&c,&d);
    		arr[x][c]=min(arr[x][c],d);
		}
		}
	for(int k=0;k<n;k++){
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				arr[i][j]=min(arr[i][j],arr[i][k]+arr[k][j]);
			}
		}
	}
	printf("0 0\n");
	for(int i=1;i<n;i++){
    printf("%d %lld\n",i,arr[0][i]);
   }
    }
	return 0;
}

C++: #include <iostream>
#include <queue>
#include <vector>
#include <utility>
using namespace std;
typedef pair<int, int> P;
struct edge {int to, cost;};
const int INF = (1 << 28);
int n;
vector<edge> G[110];


vector<int> dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P>> que;
    que.push(P(0, s));
    vector<int> d(n, INF);
    d[s] = 0;
    while (!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        for (auto e: G[v]) {
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
    return d;
}

int main(void) {
    cin >> n;
    for (int i = 0; i < n; i++) {
        int u, k, v, c;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            cin >> v >> c;
            G[u].push_back(edge {v, c});
        }
    }
    vector<int> d = dijkstra(0);
    for (int i = 0; i < n; i++) {
        cout << i << " " << d[i] << endl;
    }

    return 0;
}