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++: #include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

const int INF = 0xfffffff;
const int MAX = 100;

struct Edge {
	int v;
	int c;
};

int main() {
	int n;
	vector<Edge> graph[MAX];
	int table[MAX];
	bool check[MAX];

	cin >> n;
	for (int i = 0; i < n; i++) {
		table[i] = INF;
		check[i] = false;
	}

	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			Edge e;
			cin >> e.v >> e.c;
			graph[u].push_back(e);
		}
	}

	int u = 0;
	table[0] = 0;
	while (true) {
		check[u] = true;

		for (int i = 0; i < graph[u].size(); i++) {
			int v = graph[u][i].v;
			int c = graph[u][i].c;
			if (table[v] > c + table[u]) {
				table[v] = c + table[u];
			}
		}

		int m = INF;
		int prev = u;
		for (int i = 0; i < n; i++) {
			if (check[i])continue;
			if (table[i] < m) {
				m = table[i];
				u = i;
			}
		}
		if (u == prev)break;
	}

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

	return 0;
}

C++: #include <iostream>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#include <cmath>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)

#define debug(x) cerr<<#x<<": "<<x<<'\n'

#define fi first
#define se second

#define vi vector<int>
#define pb push_back
#define mp make_pair

#define pcnt __builtin_popcount

typedef long long ll;

const int inf = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

struct Edge{
    int to;
    int cost;
}
vector<int> G[110];
int d[110] = {};
int main(){
    int n;
    cin >> n;
    rep(i,n){
        int t,m;
        cin >> t >> m;
        rep(j,m){
            int a,b;
            cin >> a >> b;
            G[t].push_back({a,b})
        }
    }

    rep(i,n) d[i] = 900010000;
    d[0] = 0;
    while(true){
        bool update = false;
        rep(i,n){
            for(const auto& e: G[i]){
                if(d[i] + e.cost < d[e.to]){
                    d[e.to] = d[i]+e.cost;
                    update = true;
                }
            }
        }
        if(!update) break;
    }

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

    return 0;
}

C++: #include<stdio.h>

#define N 100
#define BLACK 0
#define WHITE 1
#define INF 100000000
#define NIL -1

void dijkstra(void);

int A[N][N],n;

int main()
{
  int u,k,v,c;

  scanf("%d",&n);

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

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

  dijkstra();

  return 0;
}

void dijkstra()
{

  int u,mincost;
  int d[N],pi[N],color[N];

  for(int u = 0; u < n; u++)
  {
    d[u] = INF;
    pi[u] = NIL;
    color[u] = WHITE;
  }

  d[0] = 0;

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

    color[u] = BLACK;

    for(int v = 0; v < n; v++)
    {
      if(color[v] != BLACK && A[u][v] + d[u] < d[v] && A[u][v] != -1){
        pi[v] = u;
        d[v] = A[u][v] +d[u];
      }
    }

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

}

C++: #include <iostream>
using namespace std;
 
#define WHITE 0 
#define GRAY 1
#define BLACK 2
#define INFTY 10000000
int n,color[100],M[100][100],d[100],p[100];
int i,j,u,k,v,c;
 
//ダイクストラ法
void dijkstra(){

  //初期化
  for( i = 0; i < n; i++ ){
    color[i] = WHITE;
    d[i] = INFTY;
  }
  d[0] = 0;
  p[0] = -1;

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

    color[u] = BLACK;
 
    //更新
    for( v = 0; v < n; v++ ){
      if( color[v] != BLACK && M[u][v] != INFTY ){
	if( d[u] + M[u][v] < d[v] ){
	  d[v] = d[u] + M[u][v];
	  p[v] = u;
	  color[v] = GRAY;
	}
      }
    }
  }
  
  //出力
  for( i = 0; i < n; i++ ){
    cout << i << " ";
    if( d[i] == INFTY ) cout << -1;
    else cout << d[i];
    cout << endl;
  }
}
 
int main(){

  //入力
  cin >> n;
  for( i = 0; i < n; i++ ){
    for( j = 0; j < n; j++ ){
      M[i][j] = INFTY;
    }
  }
 
  for( i = 0; i < n; i++ ){
    cin >> u >> k;
    for( j = 0; j < k; j++ ){
      cin >> v >> c;
      M[u][v] = c;
    }
  }
   
  dijkstra();
 
  return 0;
}

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

#define MAX 100
#define INFTY (1 << 21)
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[MAX][MAX];

void solve(void) {
    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(true) {
        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 i = 0; i < n; ++i) {
            if(color[i] != BLACK && M[u][i] != INFTY) {
                if(d[i] > d[u] + M[u][i]) {
                    d[i] = d[u] + M[u][i];
                    color[i] = GRAY;
                }
            }
        }
    }
    for(int i = 0; i < n; ++i) {
        cout << i << ' ' << (d[i] == INFTY ? -1 : d[i]) << endl;
    }
}

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