Go: package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

const (
	INFTY = 1 << 21
	NIL   = -1
)

const (
	WHITE = iota
	GRAY
	BLACK
)

type Graph [][]int

func (g *Graph) dikstra(n int) string {
	var (
		u, minv = 0, 0
	)

	d := make([]int, n)
	color := make([]int, n)

	for i := 0; i < n; i++ {
		d[i] = INFTY
		color[i] = WHITE
	}
	d[0] = 0
	color[0] = GRAY

	for {
		minv = INFTY
		u = -1
		for 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 v := 0; v < n; v++ {
			if color[v] != BLACK && (*g)[u][v] != INFTY {
				if d[v] > d[u]+(*g)[u][v] {
					d[v] = d[u] + (*g)[u][v]
					color[v] = GRAY
				}
			}
		}
	}

	var out bytes.Buffer
	for i := 0; i < n; i++ {
		out.WriteString(fmt.Sprintf("%d ", i))
		if d[i] == INFTY {
			out.WriteString(fmt.Sprintf("%d\n", -1))
			continue
		}
		out.WriteString(fmt.Sprintf("%d\n", d[i]))
	}

	return strings.TrimRight(out.String(), "\n")
}

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	g := make(Graph, n)
	for i := 0; i < n; i++ {
		g[i] = make([]int, n)
		for j := 0; j < n; j++ {
			g[i][j] = INFTY
		}
	}

	for i := 0; i < n; i++ {
		sc.Scan()
		u, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())

		for j := 0; j < k; j++ {
			sc.Scan()
			v, _ := strconv.Atoi(sc.Text())
			sc.Scan()
			c, _ := strconv.Atoi(sc.Text())

			g[u][v] = c
		}
	}

	return g.dikstra(n)
}

func main() {
	fmt.Println(answer(os.Stdin))
}

C++: #include <bits/stdc++.h>
using namespace std;

#define rep(i, n) REP(i, 0, n)
#define REP(i,k,n) for(int i = k; i < n; i++)
#define mmax(start, end) *max_element(start, end)
#define mmin(start, end) *min_element(start, end)
#define argmax max_element
#define argmin min_element
#define push push_back
#define pop pop_back
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef string str;

int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

template<class T = ll> T in() {
    T _in;
    cin >> _in;
    return _in;
}

#define EMAX 100001

int cost[101][101];

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

    ll n=in();
    int d[101];

    rep(i, n) {
        rep(j, n) {
            cost[i][j] = EMAX;
        }
        d[i] = EMAX;
    }

    rep(i, n) {
        int u=in<int>(), k=in<int>();
        rep(j, k) {
            int v=in<int>(), c=in<int>();
            cost[u][v] = c;
        }
    }

    // ノード0からの距離を調べる
    d[0] = 0;
    bool flag = true;
    while(flag) {
        flag=false;
        // 移動する方法のある全ノードからの，次のノードへの移動コストを考える
        rep(i, n) {
            if(d[i] != EMAX) {
                rep(j, n) {
                    if(i == j)
                        continue;
                    int next_c = d[i] + cost[i][j];

                    // 更新できる場合更新
                    if(d[j] > next_c) {
                        d[j] = next_c;
                        flag=true;
                    }
                }
            }
        }
    }

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

    return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
static const int MAX=100;
static const int INFTY=(1<<21);
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;

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 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;
		}
	}
	dijkstra();

	return 0;
}

C++: #include <iostream>
#include <algorithm>
#define N 110
#define INF 1000000;

int main(){
  int A[N][N];
  int n;
  std::cin >> n;

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

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

  for(int k=0; k<n; k++){
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
        A[i][j] = std::min( A[i][j], A[i][k]+A[k][j] );
      }
    }
  }

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

C++: #include <bits/stdc++.h>



using namespace std;



static const int INF = 999999;



int main(){

	int n,array[100][100];



	for(int i=0; i<100; i++){

		for(int j=0; j<100; j++){

			if(i==j) array[i][j]=0;

			else array[i][j]=INF;

		}

	}

	

	cin>>n;



	for(int i=0; i<n; i++){

		int u,k;

		cin>>u>>k;

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

			int t,c;

			cin>>t>>c;

			array[u][t]=c;

		}

	}



	int d[100];

	fill(d,d+n,INF);

	d[0]=0;

	bool flag[100]={};



	while(1){

		int u=-1,infn=INF;

		for(int i=0; i<n; i++){

			if(!flag[i] && d[i]<=infn){

				u = i;

				infn = d[u];

			}

		}

		if(u==-1) break;

		flag[u] = true;



		for(int i=0; i<n; i++){

			if(array[u][i]!=INF && !flag[i]){

				d[i] = min(d[i],d[u]+array[u][i]);

			}

		}

	}



	for(int i=0; i<n; i++){

		cout<<i<<" "<<d[i]<<endl;

	}



	return 0;

}

C++: #include<iostream>
using namespace std;
static const int MAX=100;
static const int INFTY=(1<<21);
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;

int n,M[MAX][MAX];

void dik(){
int min;
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){
min=INFTY;
int u=-1;
for(int i=0;i<n;i++){
if(min>d[i]&&color[i]!=BLACK){
u=i;
min=d[i];
}
}
if(u==-1)break;
color[u]=BLACK;
for(int v=0;v<n;v++){
if(color[v]!=BLACK&&M[u][v]){
if(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 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;
}
}

dik();

return 0;
}

C++: #include<iostream>
#define rep(i, a) for(int i=0; i<(int)(a); i++)
using namespace std;
int M[100][100];int v, n, c, e,u,r,k;
const  long long int INF = (1<<21);
 void dijkstra() {
     int miv;
     int d[100], co[100];
     rep(i, n) {
         d[i] = INF;
         co[i] = 0;
     }
     d[0] = 0;
     co[0] = 1;
     while (1) {
         miv = INF;
         int u = -1;
         rep(i, n) {
             if (miv > d[i] && co[i] != 2) {
                 u = i;
                 miv = d[i];
             }
         }
         if (u == -1)
             break;
         co[u] = 2;
         rep(v, n) {
             if (co[v] != 2 && M[u][v] != INF) {
                 if (d[v] > d[u] + M[u][v]) {
                     d[v] = d[u] + M[u][v];
                     co[v] = 1;
                 }
             }
         } 
     }
     rep(i, n) {
         cout << i << " " << (d[i] == INF ? -1 : d[i]) << endl;
     }
}
int main()
{
    cin >> n;
    rep(i, n) {
        rep(j, n) {
            M[i][j] = INF;
        }
    }
    rep(i, n) {
        cin >> u >> k;
        rep(j, k) {
            cin >> v >> c;
            M[u][v] = c;
        }
    }
    dijkstra();
}