Go: package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)

	g := makeGraph(n)
	for i := 0; i < n; i++ {
		u := getNextInt(scanner)
		k := getNextInt(scanner)
		for ii := 0; ii < k; ii++ {
			v := getNextInt(scanner)
			c := getNextInt(scanner)
			g[u][v] = c
		}
	}

	ans := make([]int, n)
	im := make(IntMap, 1)
	im.increment(0)
	for len(im) < n {
		min := 1 << 30
		x := -1
		for u := range im {
			for v := 0; v < n; v++ {
				if im.get(v) != 0 {
					continue
				}
				if min > ans[u]+g[u][v] {
					min = ans[u] + g[u][v]
					x = v
				}
			}
		}
		im.increment(x)
		ans[x] = min
	}

	for i := 0; i < n; i++ {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d", i, ans[i]))
	}
	writer.Flush()
}

func makeGraph(n int) [][]int {
	g := make([][]int, n)
	for i := 0; i < n; i++ {
		g[i] = make([]int, n)
		for ii := 0; ii < n; ii++ {
			g[i][ii] = 1 << 30
		}
	}

	return g
}

// IntMap ...
type IntMap map[int]int

func (m IntMap) get(key int) int {
	if _, ok := m[key]; ok {
		return m[key]
	}
	return 0
}
func (m IntMap) increment(key int) {
	if _, ok := m[key]; ok == false {
		m[key] = 0
	}
	m[key]++
}

C++: // Ref : https://book.mynavi.jp/ec/products/detail/id=35408

#include <iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1 << 21);
static const int WHITE = 0; // unsearched state
static const int GRAY = 1; // ungrouped state
static const int BLACK = 2; // grouped state

int n, M[MAX][MAX];

void dijkstra() {
	int minv;
	int d[MAX], color[MAX];

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

	d[0] = 0;
	color[0] = GRAY;
	while (1) {
		minv = INFTY;
		int u = -1;
		for (int i = 0; i < n; i++) {
			if (minv > d[i] && color[i] != BLACK) {
				u = i;
				minv = d[i];
			}
		}
		if (u == -1) break;
		color[u] = BLACK;
		for (int v = 0; v < n; v++) {
			if (color[v] != BLACK && M[u][v] != INFTY) {
				if (d[v] > d[u] + M[u][v]) {
					d[v] = d[u] + M[u][v];
					color[v] = GRAY;
				}
			}
		}
	}

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

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

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

	dijkstra();

	return 0;
}

C++: #include <iostream>
using namespace std;
#include <vector>
#include <utility>
#include <algorithm>
using P = pair<int,int>;
#define rep(i,n) for(int i=0;i<n;i++)
vector<bool> seen;
int main(){
    int N,t;
    cin >> N;
    vector<int> costs(N);
    vector<vector<P>> T(N,vector<P>(N));
    vector<int> v(N);
    vector<int> ved(N);
    P pa;
    rep(i,N){
       cin >> t;
       cin >> v[i];
       rep(j,v[i]){
           cin >> T[i][j].second >> T[i][j].first;
       }
       sort(T[i].begin(),T[i].begin()+v[i]);
    }
    seen.assign(N, false);
    costs.assign(N,1e9);
    seen[0] = true;
    costs[0] = 0;
    rep(i,N-1){
        pa.first = 1e9;
        rep(j,N){
            rep(k,v[j]){
                if(seen[T[j][k].second])continue;
                if(pa.first > costs[j]+T[j][k].first){
                    pa.first = costs[j]+T[j][k].first;
                    pa.second = T[j][k].second;
                }
            }
        }
        seen[pa.second] = true;
        costs[pa.second] = pa.first;
    }
    rep(i,N){
        cout << i << " " << costs[i] << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(int (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define mp make_pair
const ll MOD=1e9+7;
const int MAX = 100;
const int BLACK = 2;
const int GRAY = 1;
const int WHITE = 0;
using namespace std;

int n, M[MAX][MAX];

void dijkstra(){
  int minv;
  int color[MAX];
  //d[i] : 自集合からの点iへの最短距離
  int d[MAX];

  rep(i,n){
    color[i] = WHITE;
    d[i] = INT_MAX;
  }
  d[0] = 0;
  color[0] = GRAY;

  while(1){
    minv = INT_MAX;
    int u = -1;
    rep(i,n){
      if(color[i] != BLACK && minv > d[i]){
        u = i;
        minv = d[i];
      }
    }
    if(u == -1) break;
    color[u] = BLACK;
    rep(v,n){
      //uとvがつながっている、かつvが未探索
      if(M[u][v] != INT_MAX && color[v] != BLACK){
        if(d[v] > d[u] + M[u][v]){
          d[v] = d[u] + M[u][v];
          color[v] = GRAY;
        }
      }
    }
  }
  rep(i,n){
    cout << i << " " << (d[i] == INT_MAX ? -1 : d[i]) << endl;
  }
}

int main(){
  cin >> n;
  rep(i,n){
    rep(j,n){
      M[i][j] = INT_MAX;
    }
  }

  rep(i,n){
    int u,k;
    cin >> u >> k;
    rep(j,k){
      int v,c;
      cin >> v >> c;
      M[u][v] = c;
    }
  }
  dijkstra();
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <climits>

class Graph{
public:
	std::vector< std::vector<int> > A;
	int n;

	Graph(int n);

	void SetEdge(int a, int b, int weight);
	void SortEdge();
	void SortEdge_Rec1(int left, int right);
	void SortEdge_Rec2(int left, int mid, int right);

	std::vector<int> Dijkstra();

};

Graph::Graph(int n){
	A.resize(n);
	for (int i = 0; i < n; i++) A[i].resize(n, -1);
	this->n = n;
}

void Graph::SetEdge(int a, int b, int weight){
	A[a][b] = weight;
	return;
}
/*
void Graph::SortEdge(){
	SortEdge_Rec1(0, A.size());
}

void Graph::SortEdge_Rec1(int left, int right){
	if (left + 1 < right){
		int mid = (left + right) / 2;
		SortEdge_Rec1(left, mid);
		SortEdge_Rec1(mid, right);
		SortEdge_Rec2(left, mid, right);
	}
}

void Graph::SortEdge_Rec2(int left, int mid, int right){
	int n1 = mid - left;
	int n2 = right - mid;
	std::vector< std::vector<int> > L(n1 + 1);
	for (int i = 0; i < n1; i++) L[i] = A[left + i];
	std::vector< std::vector<int> > R(n2 + 1);
	for (int i = 0; i < n2; i++) R[i] = A[mid + i];
	std::vector<int> x;
	x.push_back(0); x.push_back(0); x.push_back(INFTY);
	L[n1] = x;
	R[n2] = x;
	int i = 0;
	int j = 0;
	for (int k = left; k < right; k++){
		if (L[i][2] <= R[j][2]){
			A[k] = L[i];
			i = i + 1;
		}
		else{
			A[k] = R[j];
			j = j + 1;
		}
	}
}
*/
std::vector<int> Graph::Dijkstra(){
	std::vector<int> d(n, INT_MAX), prev(n, -1), Q(n, 0);
	d[0] = 0;
	for (int i = 0; i < n; i++) Q[i] = i;

	while (!Q.empty()){
		int mini, minu;
		for (int i = 0; i < Q.size(); i++){
			if (i == 0 || d[Q[i]] < d[minu]){
				minu = Q[i];
				mini = i;
			}
		}
		Q.erase(Q.begin() + mini);
		for (int i = 0; i < n; i++){
			if (A[minu][i] != -1){
				if (d[i] > d[minu] + A[minu][i]){
					d[i] = d[minu] + A[minu][i];
					prev[i] = minu;
				}
			}
		}
	}
	return d;
}

int main(){
	int n, u, k, v, c;
	scanf("%d", &n);
	Graph G(n);
	for (int i = 0; i < n; i++){
		scanf("%d%d", &u, &k);
		for (int j = 0; j < k; j++){
			scanf("%d%d", &v, &c);
			G.SetEdge(u, v, c);
		}
	}
	std::vector<int> result = G.Dijkstra();
	for (int i = 0; i < n; i++) printf("%d %d\n", i, result[i]);

	return 0;
}