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++: /*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define mp make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n) 
#define SIZE(x) ((int)(x).size())
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef pair<int, int> pint;
typedef pair<lint, lint> plint;
typedef vector<lint> vec;
typedef vector<vector<lint>> matrix;
typedef priority_queue<lint> p_que;
typedef priority_queue<lint, vector<lint>, greater<lint>> p_que_rev;
const lint INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

// Graph Templates
using Weight = lint;
// using Flow = int;
struct Edge {
    int src, dst;
    Weight weight;
    // Flow cap;
    Edge() : src(0), dst(0), weight(0) {}
    Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;
// const Weight INF = numeric_limits<Weight>::max() / 8;

// add edge a <--(weight = w)--> b
void add_edge(Graph &g, int a, int b, Weight w) {
    g[a].push_back(Edge(a, b, w));
    g[b].push_back(Edge(b, a, w));
}

// add edge a --(weight = w)--> b
void add_arc(Graph &g, int a, int b, Weight w) { g[a].push_back(Edge(a, b, w)); }

// Dijkstra
// g is graph, s is start
vector<Weight> dijkstra(const Graph &g, int s) {
    // const Weight INF = numeric_limits<Weight>::max() / 8;
    using state = tuple<Weight, int>;
    priority_queue<state> q;
    vector<Weight> dist(g.size(), LINF);
    dist[s] = 0;
    q.emplace(0, s);
    while (q.size()) {
        Weight d;
        int v;
        tie(d, v) = q.top();
        q.pop();
        d *= -1;
        /* if(v == t) return d; */
        if (dist[v] < d) continue;
        for (auto &e : g[v]) {
            if (dist[e.dst] > dist[v] + e.weight) {
                dist[e.dst] = dist[v] + e.weight;
                q.emplace(-dist[e.dst], e.dst);
            }
        }
    }
    return dist;
}

int main(){
    int n;
    cin >> n;
    int u, k, v;
    Weight c;
    Graph g;
    vector<Weight> dist;
    g.resize(n);
    for (int i=0; i<n; ++i){
        cin >> u >> k;
        for (int j=0; j<k; ++j){
            cin >> v >> c;
            add_arc(g, u, v, c);
        }
        // add_edge(g, s, t, d);
    }
    dist = dijkstra(g, 0);
    for (int i=0; i<(int)dist.size(); ++i){
        cout << i << " ";
        if(dist[i] != INF){
            cout << dist[i] << endl;
        }
        else {
            cout << "INF" << endl;
        }
    }
    
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
const int maxn = 111;
int mp[maxn][maxn];
#define INF 0x3f3f3f3f;
int main()
{
	int n;
	cin >> n;
	for (int i = 0;i < n;i++) {
		for (int j = 0;j < n;j++) {
			if (i == j)mp[i][j] = 0;
			else
				mp[i][j] = INF;
		}
	}
	for (int i = 0;i < n;i++)
	{
		int a, k, b, w;
		cin >> a >> k;
		for (int j = 0;j < k;j++)
		{
			cin >> b >> w;
			if(mp[a][b]>w)
			mp[a][b] = mp[b][a] = w;
		}
	}
	for (int k = 0;k < n;k++)
	{
		for (int i = 0;i < n;i++)
		{
			for (int j = 0;j < n;j++)
			{
				if (mp[i][k] + mp[k][j] < mp[i][j])
				{
					mp[i][j] = mp[i][k] + mp[k][j];
				}
			}
		}
	}
	for (int i = 0;i < n;i++)
	{
		cout<<i <<" "<< mp[0][i] << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <limits>

constexpr int MAXN = 100;
int G[MAXN][MAXN];
int P[MAXN];
int D[MAXN];
int C[MAXN];

constexpr int MAXINT = 100001;

int main() {
    int n;
    std::cin >> n;

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

    for (int i = 0; i < n; i++) {
        D[i] = MAXINT;
    }

    for (int i = 0; i < n; i++) {
        int id, e_num;
        std::cin >> id >> e_num;
        for (int j = 0; j < e_num; j++) {
            int t;
            std::cin >> t;
            std::cin >> G[id][t];
        }
    }

    int r = 0;
    D[r] = 0;
    while (true) {
        int mincost = MAXINT;
        int m;
        for (int i = 0; i < n; i++) {
            if ((C[i] == 0) && (D[i] < mincost)) {
                mincost = D[i];
                m = i;
            }
        }

        if (mincost == MAXINT) {
            break;
        }

        C[m] = 1;
        for (int i = 0; i < n; i++) {
            if ((C[i] != 1) && (G[m][i] != MAXINT)&& ((D[m] + G[m][i]) < D[i])) {
                P[i] = m;
                D[i] = D[m] + G[m][i];
            }
        }
    }

    for (int i = 0; i < n; i++) {
        std::cout << i << " " << D[i] << std::endl;
    }

}

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

int n;					//えぬ
int a[100][100] = {0};	//辺の重さ
int f[100] = {0};		//その頂点が調査済みかどうか

int main(){
	cin >> n;
	//まず辺の重さをaに入れる
	for ( int i = 0; i < n; i++ ) {
		for ( int j = 0; j < n; j++ ) {
			a[i][j] = -1;
		}
	}
	a[0][0] = 0;
	for ( int i = 0; i < n; i++ ) {
		int u;
		cin >> u;
		int k;
		cin >> k;
		for ( int j = 0; j < k; j++ ) {
			int v;
			cin >> v;
			cin >> a[u][v];
		}
	}
	for ( int i = 0; i < n - 1; i++ ) {
		int k = -1;
		int v = 0;
		for ( int j = 1; j < n; j++ ) {
			if ( a[0][j] == -1 || f[j] == 1 ) continue;
			if ( k == -1 || a[0][j] < k ) {
				v = j;
				k = a[0][j];
			}
		}
		f[v] = 1;
		for ( int j = 1; j < n; j++ ) {
			if ( v == j ) continue;
			if ( a[v][j] == -1 || f[j] == 1 ) continue;
			if ( a[0][j] == -1 || a[0][j] > a[0][v] + a[v][j] ) {
				a[0][j] = a[0][v] + a[v][j];
			}
		}
	}
	for ( int i = 0; i < n; i++ ) {
		cout << i << " " << a[0][i] << endl;
	}
	return 0;
}