Go: package main

import (
	"bufio"
	"fmt"
	"os"
)

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 := make(map[int]int)
	q[0] = 0
	visited := make(map[int]struct{})
	out := make([]int, n)

	for len(q) > 0 {
		u := top(q)
		for uu, c := range cs[u] {
			// Consider the connection between u and uu.
			if _, ok := visited[uu]; ok {
				continue
			}
			if d, ok := q[uu]; !ok || d > q[u]+c {
				q[uu] = q[u] + c
			}
		}

		out[u] = q[u]
		delete(q, u)
		visited[u] = struct{}{}
	}

	for u, d := range out {
		fmt.Println(u, d)
	}
}

func top(q map[int]int) int {
	minu := -1
	min := -1
	for u, d := range q {
		if min < 0 || d < min {
			minu = u
			min = d
		}
	}

	return minu
}

C++: #include<bits/stdc++.h>
//#include<iostream>
using namespace std;
//type
typedef long long ll;
#define pii pair<int, int>
#define vi vector<int>
//x * y * 1.0 can cause overflow
//constant
#define inf (int)(1e9+7)
#define mod (ll)(1e9+7)
#define eps 1e-10
//omission
#define eb emplace_back
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define all(v) v.begin(), v.end()
#define ios cin.tie(0); ios::sync_with_stdio(false)
#define FIX(a) cout << fixed << setprecision(a)
#define mp make_pair
//manip
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(unique(v.begin(), v.end(), v.end());
#define fill(x, y) memset(x, y, sizeof(x))
#define ceil(a, b) a / b + !!(a % b)
template<class T> T power_mod(T a, T b) {return b ? power(a * a % inf, b / 2) * (b % 2 ? a : 1) % inf : 1;}
template<class T> T power(T a, T b) {return b ? power(a * a, b / 2) * (b % 2 ? a : 1) : 1;}
#define LB(v, x) (int)(lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (int)(upper_bound(v.begin(), v.end(), x) - v.begin())
template<typename T> T gcd(T a, T b) {if (b == 0) return a; return gcd(b, a % b);}
template<typename T> T lcm(T a, T b) {return a / gcd(max(a, b), min(a, b)) * b;} //先に割る!!
#define outa(a, n) rep(i_, n) cout << a[i_] << " "; cout << endl
#define out(a) cout << a << endl
#define outv(v) rep(i, SZ(v)) cout << v[i] << " "; cout << endl
//loop
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep3(i, st, n) for (int i = st; i < n; ++i)
//algorithm
//double pointer, l start, how many adds, can be 0 -> init r = l, sum = 0
//bfs, not x, y, i, j
//not !(i % 2), i % 2 == 0
//minimal required terms
//cast caution
//look constraints always
//ctrl + command + e -> 変数一括変更



int main() {
    
    
   
    int n; cin >> n;
    int table[101][101]; fill_n(*table, 101 * 101, inf);
    rep(i, 101) table[i][i] = 0;
    vector<vector<pii> > edge(n);
    rep(i, n) {
        int u, k; cin >> u >> k;
        rep(j, k) {
            int v, c; cin >> v >> c;
            edge[u].eb(v, c);
        }
        
    }
    
    while (1) {
        int update = 0;
        rep(from, n) {
            rep(j, SZ(edge[from])) {
                int to = edge[from][j].F;
                int cost = edge[from][j].S;
                
                if (table[0][to] > table[0][from] + cost) {
                    update = 1;
                    table[0][to] = table[0][from] + cost;
                }
            }
        }
        if (update == 0) break;
    }
    
    out(0 << " " << 0);
    rep3(i, 1, n) out(i << " " << table[0][i]);
        
        
    
    
    
}

C++: #include <iostream>
#include <vector>
using namespace std;
#define WHITE 0
#define GRAY 1
#define BLACK 2
static const int INF = 1<<21;
int main(int argc, const char * argv[]) {
    int n;
    cin >> n;
    int G[n][n];
    int d[n];
    int p[n];
    int color[n];
    for(int i=0;i<n;i++){
        for (int j=0; j<n; j++) {
            G[i][j] = -1;
        }
    }
    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;
            G[u][v] = c;
        }
    }
    
    for (int i=0; i<n; i++) {
        color[i] = WHITE;
        p[i] = -1;
        d[i] = INF;
    }
    
    while(true){
        d[0] = 0;
        p[0] = 0;//?
        int u;
        int mincost = INF;
        //???????????????????±????
        for(int i=0;i<n;i++){
            if(d[i]<mincost && color[i]!=BLACK){
                mincost = d[i];
                u = i;
            }
        }
        color[u] = BLACK;
        if(mincost==INF) break;//?¶????????????????????????°??±?????£????????¨???
        
        for(int v=0;v<n;v++){
            if(G[u][v] != -1 && d[v]>d[u]+G[u][v]){
               d[v] = d[u] + G[u][v];
               color[v] = GRAY;//??????????????????
               p[v] = u;
            }
        }
    }
    for(int i=0;i<n;i++){
        cout <<  i << " " << d[i] << endl;
    }
    return 0;
}

C++: #include <cstdio>
#include <queue>
#include <vector>
using namespace std;
#define INF 1 << 30
typedef pair<int, int> P;

int n, M[100][100], d[100];

void dijkstra(void) {
    int i, u, v;
    P t;
    priority_queue<P, vector<P>, greater<P> > pq;

    pq.push(make_pair(0, 0));
    while (!pq.empty()) {
        t = pq.top(); pq.pop();
        v = t.first;
        u = t.second;

        if (d[u] != INF) continue;
        d[u] = v;

        for (i = 0; i < n; i++) {
            if (d[i] != INF || M[u][i] == INF) continue;
            pq.push(make_pair(v + M[u][i], i));
        }
    }
}

int main(void) {
    int i, j, u, k, v, c;
    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        d[i] = INF;
        for (j = 0; j < n; j++) M[i][j] = INF;
    }

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

    dijkstra();

    for (i = 0; i < n; i++) printf("%d %d\n", i, d[i]);

    return 0;
}

C++: #include <iostream>
using namespace std;
int n,m[100][100],d[100];
void mins(){
    int u,min,color[100];
    for(int i=0;i<n;i++){
        d[i]=1000000000;
        color[i]=1;
    }
    d[0]=0;
    while(1){
        min=1000000000;
        u=-1;
        for(int i=0;i<n;i++){
            if(color[i]!=3&&d[i]<min){
                u=i;
                min=d[i];
            }
        }
        if(u==-1){
            break;
        }
        color[u]=3;
        for(int i=0;i<n;i++){
            if(m[u][i]!=-1){
                if(d[i]>min+m[u][i]){
                    d[i]=min+m[u][i];
                }
            }
        }
    }
}
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            m[i][j]=-1;
        }
    }
    int a,k,c,v;
    for(int i=0;i<n;i++){
        cin>>a>>k;
        for(int j=0;j<k;j++){
            cin>>c>>v;
            m[a][c]=v;
        }
    }
    mins();
    for(int i=0;i<n;i++){
        cout<<i<<" "<<d[i]<<endl;
    }
    return 0;
}

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

int x[1000][1000];
int y[1000];

int main() {
	memset(x, 127, sizeof(x));
	memset(y, 127, sizeof(y));
	int n, a, b, c, d;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		for (int i = 0; i < b; i++) {
			cin >> c >> d;
			x[a][c] = d;
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < n; k++) {
				y[k] = min(y[k], y[j] + x[j][k]);
			}
		}
	}
	for (int i = 0; i < n; i++) {
		cout << i << ' ' << y[i] << endl;
	}
	return 0;
}