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>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;
const int maxn=100+10;
const int maxv=10000+10;
const int INF=1<<21;
int n;
int E;
typedef struct
{
    int from,to,cost;
}Edge;

Edge e[maxv];
int d[maxn];
void bellman_ford(int s)
{
    fill(d,d+n,INF);
    d[s]=0;
    while(true)
    {
        bool bUpdate=false;
        for(int i=0;i<E;i++)
        {
            Edge es=e[i];
            if(d[es.from]!=INF&&d[es.to]>d[es.from]+es.cost)
            {
                d[es.to]=d[es.from]+es.cost;
                bUpdate=true;

            }
        }
        if(!bUpdate) break;

    }
    for(int i=0;i<n;i++)
    printf("%d %d\n",i,d[i]);
}
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d",&n);
    int id,c;
    E=0;
    for(int i=0; i<n; i++)
    {
        scanf("%d%d",&id,&c);
        while(c--)
        {
            scanf("%d%d",&e[E].to,&e[E].cost);
            e[E].from=id;
            E++;
        }
    }
    bellman_ford(0);

    return 0;
}

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

int min(int i,int j){
 return i>j?j:i;
}

int main(void){
 int n,u,k,c,v;
 vector<int> d;
 vector< vector<int> > edge;
 cin>>n;
 edge.resize(n);
 for(int i=0;i<n;i++){
 edge[i].resize(n);
}
 d.resize(n);
 d[0]=0;
 for(int i=1;i<n;i++){
  d[i]=100000000;
}
 for(int i=0;i<n;i++){
  for(int j=0;j<n;j++){
   edge[i][j]=1000000000;
  }
}
for(int i=0;i<n;i++){
 edge[i][i]=0;
}
for(int i=0;i<n;i++){
 cin>>u>>k;
 for(int j=0;j<k;j++){
  cin>>v>>c;
  edge[u][v]=c;
 }
}
for(int i=0;i<n;i++){
 for(int j=0;j<n;j++){
  for(int k=0;k<i;k++){
  d[j]=min(d[j],d[k]+edge[k][j]);}
 }
}

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;
const ll INF = 1e18;
const int inf = 1e9;
#define rep(i, n) for (int i = 0; i < n; i++)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

const int MAX = 100;
int cost[MAX][MAX];
int n;

void dijkstra() {
    int d[n];
    bool seen[n] = {};
    rep (i, n) { d[i] = inf; }
    d[0] = 0;
    while (1) {
        int minc = inf, now;
        rep (i, n) {
            if (minc > d[i] && !seen[i]) {
                minc = d[i];
                now = i;
            }
        }
        seen[now] = 1;
        if (minc == inf) break;
        rep (i, n) {
            if (cost[now][i] != inf && !seen[i]) {
                if (d[i] > cost[now][i] + d[now]) {
                    d[i] = cost[now][i] + d[now];
                }
            }
        }
    }
    rep (i, n) { cout << i << " " << d[i] << "\n"; }
    return;
}

int main() {
    cin >> n;
    rep (i, n) rep (j, n) cost[i][j] = inf;
    rep (i, n) {
        int now, k, next, c;
        cin >> now >> k;
        rep (i, k) {
            cin >> next >> c;
            cost[now][next] = c;
        }
    }
    dijkstra();
}