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 <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;
typedef pair<int, int> P;  //firstは最短距離,secondは頂点番号

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

struct edge{
	int to,cost;
	edge(){to=0;cost=0;}
};

class dijkstra{
public:
	vector<vector<edge> > E;
	vector<int> dist;
	int start;
	dijkstra(int n): E(n),dist(n){}

	void add_edge(int x,int y,int c){
		edge e;
		e.to = y,e.cost = c;
		E[x].push_back(e);
	}

	void shortest_path(){
		priority_queue<P,vector<P>,greater<P> > que;
		dist.assign(dist.size(),INF);

		dist[start] = 0;
		que.push(P(0,start));

		while(!que.empty()){
			 P p = que.top();
			 que.pop();
			 int v = p.second;
			 if(dist[v] < p.first) continue;

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


};

int main()
{
	int n;
	cin >> n;
	dijkstra dij(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;
			dij.add_edge(u,v,c);
		}
	}

	dij.start = 0;
	dij.shortest_path();

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

	return 0;
}

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

int G[110][110] = {};
int mini[110];
int used[110];

void dijkstra(int n)
{
    //init
    for(int i = 0;i < n;i++){
        mini[i] = INF;
        used[i] = 0;
    }
    mini[0] = 0;

    while(true)
    {
        int v = -1;
        for(int i = 0;i < n;i++){
            if(!used[i] && (v == -1 || mini[i] < mini[v])) v = i;
        }
        if(v == -1) break;
        used[v] = 1;

        for(int i = 0;i < n;i++){
            mini[i] = min(mini[i], mini[v]+G[v][i]);
        }
    }
}

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

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

    for(int i = 0;i < n;i++){
        cin >> u >> k;
        for(int j = 0;j < k;j++){
            cin >> v >> c;
            G[u][v] = c; //uiとviをつなぐコストがci
        }
    }
    dijkstra(n);
    
    for(int i = 0;i < n;i++) printf("%d %d\n", i, mini[i]);
    
    return 0;
}

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

struct uft{
    vector<ll> par;
    uft(ll n) {
        par.resize(n);
        rep(i,n)par[i]=i;
    }

    ll find(ll a){
        if(par[a]==a){
            return a;
        }else {
            return find(par[a]);
        }
    }

    void unite(ll a,ll b){
        par[find(a)]=find(b);
    }

    bool same(ll a,ll b){
        return find(a) == find(b);
    }
};

struct edge{
    ll s,t,w;
};

bool sortw(edge a,edge b) {
    return a.w < b.w;
}

int main() {
    const ll inf = 1e12;
    ll n;
    cin>>n;
    vector<vector<ll>> matrix(n,vector<ll>(n));
    rep(i,n){
        rep(j,n){
            if(i==j){
                matrix[i][j]=0;
            }else{
                matrix[i][j]=inf;
            }
        }
    }
    rep(i,n) {
        ll u,k;
        cin>>u>>k;
        rep(j,k){
            ll c,w;
            cin>>c>>w;
            matrix[u][c]=w;
        }
    }
    rep(k,n){
        rep(i,n){
            rep(j,n){
                if(matrix[i][k]<inf && matrix[k][j]<inf && matrix[i][j]>matrix[i][k]+matrix[k][j]){
                    matrix[i][j]=matrix[i][k]+matrix[k][j];
                }
            }
        }
    }
    rep(i,n){
        cout<<i<<" "<<matrix[0][i]<<endl;
    }
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
#define int(x) int x; scanf("%d",&x)
#define input(x) scanf("%d",&x)
#define rep(x,n) for(int x = 0; x < n; x++)
#define _br printf("\n")
#define INF 2000000000

vector<pair<int,int> > PathList[100];
int d[100];
bool complete[100];

void dijkstra(int n,vector<pair<int,int> > PathList[]){
    rep(i,n){
        d[i] = INF;
        complete[i] = false;
    }
    d[0] = 0;
    
    int count = 0;
    
    while (count != n) {
        int mind = INF;
        int mindi = 0;
        rep(i,n){
            if (!complete[i] && d[i] < mind) {
                mind = d[i];
                mindi = i;
            }
        }
        
        complete[mindi] = true;
        count++;
        
        rep(i,PathList[mindi].size()){
            if (PathList[mindi][i].second + d[mindi] < d[PathList[mindi][i].first]) {
                d[PathList[mindi][i].first] = PathList[mindi][i].second + d[mindi];
            }
        }
    }
}


int main(){
    int(n);
    rep(i,n){
        int(k);int(num);
        rep(j,num){
            int(s);int(t);
            PathList[i].push_back(make_pair(s,t));
        }
    }
    
    dijkstra(n,PathList);
    
    rep(i,n){
        printf("%d %d\n",i,d[i]);
    }
    
    return 0;
}