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>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
constexpr int MAX = 100;
enum Color { WHITE = 0, GRAY, BLACK };
int n;
vv(int, M, MAX, MAX, INT_MAX);
inline void dijkstra() {
	vi d(MAX, INT_MAX), color(MAX, WHITE);
	d[0] = 0;
	color[0] = GRAY;
	int minv, u;
	while(true) {
		minv = INT_MAX;
		u = -1;
		rep(i, 0, n) {
			if(minv > d[i] && color[i] != BLACK) {
				u = i;
				minv = d[i];
			}
		}
		if(u == -1) break;
		color[u] = BLACK;
		rep(v, 0, n) {
			if(color[v] != BLACK && M[u][v] != INT_MAX && d[v] > d[u] + M[u][v]) {
				d[v] = d[u] + M[u][v];
				color[v] = GRAY;
			}
		}
	}
	rep(i, 0, n) {
		cout << i << " " << (d[i] == INT_MAX ? -1 : d[i]) << endl;
	}
}
int main() {
	cin >> n;
	int u, k, v, c;
	rep(i, 0, n) {
		cin >> u >> k;
		rep(j, 0, k) {
			cin >> v >> c;
			M[u][v] = c;
		}
	}
	dijkstra();
	return 0;
}

C++: #include <iostream>

using namespace std;

#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INFTY 99999999

int color[MAX];
int M[MAX][MAX];
int d[MAX];
int p[MAX];
int n;

int dijkstra(int s)
{

	int mincost;
	int u;

	for (int i = 0; i < n; i++) {
		d[i] = INFTY;
		p[i] = -1;
	}
	d[s] = 0;

	while (true) {
		mincost = INFTY;

		for (int i = 0; i < n; i++) {
			if (color[i] != BLACK&&d[i] < mincost) {
				mincost = d[i];
				u = i;
			}
		}

		if (mincost == INFTY) {
			break;
		}

		color[u] = BLACK;

		for (int i = 0; i < n; i++) {
			if (color[i] != BLACK&&M[u][i] != INFTY) {
				if (d[u] + M[u][i] < d[i]) {
					d[i] = d[u] + M[u][i];
					p[i] = u;
					color[i] = GRAY;
				}
			}
		}


	}


	int sum = 0;

	for (int i = 0; i < n; i++) {
		sum += d[i];
	}

	return sum;


}

int main(void)
{

	cin >> n;

	int u;
	int k;
	int v;

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


	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			cin >> v;
			cin >> M[u][v];
		}
	}

	dijkstra(0);

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

	return 0;
}

C++: #include <iostream>
#include <array>
#include <vector>
#include <algorithm>

int n;
static const int nmax = 2005;
static const int INFTY = (1<<21);
static const int WHITE = 0; // Not visited
static const int GRAY = 1;  // Visited
static const int BLACK = 2; // In MST
std::array<std::array<int, nmax>, nmax> adjmat;
std::array<int, nmax> d, p;
std::array<int, nmax> color;

void dijklstra(int v)
{
  color.fill(WHITE);
  d.fill(INFTY);
  p.fill(-1);

  d[v] = 0;
  color[v] = GRAY;

  while (true)
    {
      auto mincost = INFTY;

      // Find minimum cost vertex from current MST
      for (int i=0; i<n; ++i)
        {
          if (color[i] != BLACK && d[i] < mincost)
            {
              mincost = d[i];
              v = i;
            }
        }
      //std::cout << v << std::endl;
      //std::for_each(d.begin(), d.begin()+n, [](auto x){std::cout << x << ' ';});
      //std::cout << std::endl;
      // Break if no update
      if (mincost == INFTY) break;

      // Include v in MST
      color[v] = BLACK;

      // Update minimum cost outside current MST
      for (int i=0; i<n; ++i)
        {
          if ( (color[i] != BLACK) && ((d[v] + adjmat[v][i]) < d[i]))
            {
              d[i] = d[v] + adjmat[v][i];
              color[i] = GRAY;
              p[i] = v;
            }
        }
    }
}

void print_distance(int v)
{
  dijklstra(v);

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

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

  for (int i=0; i<n; ++i){
    for (int j=0; j<n; ++j)
      adjmat[i][j] = INFTY;
  }
  for (int i=0; i<n; ++i)
    {
      int u, k;
      std::cin >> u >> k;
      for (int j=0; j<k; ++j)
        {
          int v, c;
          std::cin >> v >> c;
          adjmat[u][v] = c;
        }
    }

  print_distance(0);
}