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 <iostream>
using namespace std;
#include <algorithm>
#include <cstring>
#define INF 1000000

int flg[100];

bool check(int p){

	if (flg[p] == 1) return false;
	return true;
}

int main(void){

	int n;

	cin >> n;
	int u, k;
	int date[100][100]; //date[??????????????????][?????´?????????]
	int dis[100]; //0????????????????????????????????¢

	memset(date, INF, sizeof(date));
	memset(dis, INF, sizeof(dis));
	memset(flg, 0, sizeof(flg));
	date[0][0] = 0;
	dis[0] = 0;
	for (int i = 0; i < n; i++){

		cin >> u >> k;
		for (int j = 0; j < k; j++){

			int v, c;
			cin >> v >> c;
			date[u][v] = c;
		}
	}

	while(1){
		int mini = INF;
		int p = -1;
		for (int i = 0; i < n; i++){
			if (check(i) && mini > dis[i]){
				p = i;
				mini = dis[i];
			}
		}
		if (p == -1) break;
		flg[p] = 1;
		for (int i = 0; i < n; i++){
			if (check(i) && dis[i] > dis[p] + date[p][i]){
				dis[i] = dis[p] + date[p][i];
			}
		}
	}

	for (int i = 0; i < n; i++){
		cout << i << ' ' << dis[i] << endl;
	}
}

C++: #include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;

struct edge {
    ll to;
    ll cost;
};

int N;
vector<vector<edge>> G;
vector<ll> d(150);

void dijkstra() {
    d.assign(N, INF);
    d[0] = 0;
    vector<bool> seen(N, false);
    while (true) {
        ll minv = INF;
        int v = -1;
        rep(i, N) {
            if (!seen[i] && minv > d[i]) {
                v = i;
                minv = d[i];
            }
        }

        if (v == -1)
            break;
        seen[v] = true;
        for (int i = 0; i < G[v].size(); i++) {
            edge e = G[v][i];
            if (seen[e.to])
                continue;
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
            }
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N;
    G.resize(N);
    rep(i, N) {
        ll a, b;
        cin >> a >> b;
        rep(j, b) {
            ll c, d;
            cin >> c >> d;
            G[a].push_back({c, d});
        }
    }

    dijkstra();
    rep(i, N) { cout << i << " " << d[i] << endl; }
}

C++: #include <iostream>

#define N_MAX 101
#define INF 100000000

using namespace std;

int main(){
  int n; cin >> n;
  int G[n][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 i=1;i<=k;i++){
      int v,c; cin >> v >> c;
      G[u][v]=c;
    }
  }
  //dijkstra's algorithm
  int visited[n],d[n];
  for(int i=0;i<n;i++){
    visited[i]=0;
    d[i]=INF;
  }
  d[0]=0;

  while(1){
    int mind=INF;
    int u;
    for(int i=0;i<n;i++){
      if(visited[i]==0 && d[i]<mind){
        mind=d[i];
        u=i;
      }
    }
    if(mind==INF) break;
    visited[u]=1;
    for(int v=0;v<n;v++){
      if(G[u][v]!=-1 && visited[v]==0){
        if(d[u]+G[u][v]<d[v]) d[v]=d[u]+G[u][v];
      }
    }
  }
  for(int i=0;i<n;i++) cout << i << " " << d[i] << endl;
}

C++: #include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <limits>
#include <cmath>
#include <numeric>
#include <string>

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
#define rep(i, a, b) for(int i = (a); i < (b); ++i )
#define rrep(i, a, b) for(int i = (a); i > (b); --i )
#define REP(i, a, b) for(int i = (a); i <= (b); ++i )
#define RREP(i, a, b) for(int i = (a); i >= (b); --i )
#define llrep(i, a, b) for(ll i = (a); i < (b); ++i )
#define llrrep(i, a, b) for(ll i = (a); i > (b); --i )
#define llREP(i, a, b) for(ll i = (a); i <= (b); ++i )
#define llRREP(i, a, b) for(ll i = (a); i >= (b); --i )
#define ullrep(i, a, b) for(ull i = (a); i < (b); ++i )
#define ullrrep(i, a, b) for(ull i = (a); i > (b); --i )
#define ullREP(i, a, b) for(ull i = (a); i <= (b); ++i )
#define ullRREP(i, a, b) for(ull i = (a); i >= (b); --i )

class UnionFind {
public:
    UnionFind(unsigned long long n) : rank_(n, 0), p_(n, 0) {
        rep(i, 0, n) {
            MakeSet(i);
        }
    }

    void MakeSet(int x) {
        p_[x] = x;
        rank_[x] = 0;
    }

    bool Same(int x, int y) {
        return FindSet(x) == FindSet(y);
    }

    void Link(int x, int y) {
        if (rank_[x] > rank_[y]) {
            p_[y] = x;
        } else {
            p_[x] = y;
            if (rank_[x] == rank_[y]) {
                rank_[y]++;
            }
        }
    }

    void Unite(int x, int y) {
        Link(FindSet(x), FindSet(y));
    }

    int FindSet(int x) {
        if (x != p_[x]) {
            p_[x] = FindSet(p_[x]);
        }
        return p_[x];
    }

private:
    std::vector<int> rank_, p_;
};

int N, Q;

int G[100][100];
int d[100];
int p[100];
int c[100];

int main() {
    cin >> N;
    rep(i, 0, N) {
        rep(j, 0, N) {
            G[i][j] = 10000010;
        }
    }
    rep(i, 0, N) {
        int u, k;
        cin >> u >> k;
        rep(j, 0, k) {
            int t, d;
            cin >> t >> d;
            G[u][t] = d;
        }
    }
    rep(i, 0, N) {
        d[i] = numeric_limits<int>::max();
    }

    d[0] = 0;
    p[0] = 0;
    while (true) {
        int m = -1;
        int min_d = numeric_limits<int>::max();
        rep(i, 0, N) {
            if ((c[i] == 0) && (min_d > d[i])) {
                min_d = d[i];
                m = i;
            }
        }
        if (m < 0) {
            break;
        }
        c[m] = 1;
        rep(i, 0, N) {
            if ((d[m] + G[m][i]) < d[i]) {
                d[i] = d[m] + G[m][i];
                p[i] = m;
            }
        }
    }
    rep(i, 0, N) {
        cout << i << " " << d[i] << endl;
    }
}