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 <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define stpr setprecision
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ld EPS=10e-8;
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

ll N,A[107][107];
ll DKSTR[107],chek[107];

void dikstra(){
    DKSTR[0]=0;
    ll C=1,key=0;
    vector<pair<ll,ll>> V;
    while(C<N){
        chek[key]=1;
        V.clear();
        rep(i,N){
            DKSTR[i]=min(DKSTR[i],DKSTR[key]+A[key][i]);
            if(chek[i]==0){
                V.pb(mp(DKSTR[i],i));
            }
        }
        sort(ALL(V));
        while(1){
            key=V[0].second;
            C++;
            break;
        }
    }
}

int main(){
    ll X,Y,a,b;
    cin>>N;
    rep(i,N+1){
        rep(j,N+1){
            A[i][j]=MOD;
        }
        DKSTR[i]=MOD;
    }
    rep(i,N){
        cin >> X >> Y;
        rep(j,Y){
            cin >> a >> b;
            A[X][a]=b;
        }
    }
    dikstra();
    rep(i,N){
        cout << i << " " << DKSTR[i] << endl;
    }
}

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 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>
using namespace std;

#define N 100
#define INFTY 10000001
#define WHITE 0
#define GRAY 1
#define BLACK 2

void dijkstra(int n, int d[], int M[N][N]) {
  int i, vertex, min_d, color[N];
  // 初期状態
  for (i = 0; i < n; i++) {
    d[i] = INFTY;
    color[i] = WHITE;
  }
  d[0] = 0;
  color[0] = GRAY;

  while (1) {
    // S - V でコスト最小の頂点を選ぶ
    vertex = -1;
    min_d = INFTY;
    for (i = 0; i < n; i++) {
      if (color[i] == GRAY && d[i] < min_d) {
        min_d = d[i];
        vertex = i;
      }
    }
    // S = V の場合は終了
    if (vertex == -1) break;

    // vertexをSに追加
    color[vertex] = BLACK;

    // S-Vに属し、vertexに隣接する頂点のコストを更新
    for (i = 0; i < n; i++) {
      if (color[i] != BLACK && M[vertex][i] < INFTY) {
        color[i] = GRAY;
        if (d[i] > d[vertex] + M[vertex][i]) {
          d[i] = d[vertex] + M[vertex][i];
        }
      }
    }
  }
}

int main() {
  int i, j, n, u, k, v, c, d[N], M[N][N];

  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(n, d, M);

  for (i = 0; i < n; i++) cout << i << " " << d[i] << endl;    

  return 0;
}

C++: #include <iostream>
#include <cstring>
#define MAX 120000
using namespace std;

int matrix[105][105],n,closest[105],close[105];

void djst(){
    int i,j,k;
    for(i=1;i<n;i++){
        if(matrix[0][i]<MAX)close[i]=matrix[0][i];
    }
    while(1){
        int mi=MAX,rec=-1;
        for(i=1;i<n;i++){
            if(close[i]<mi&&closest[i]==-1){
                mi=close[i];
                rec=i;
            }
        }
        if(rec==-1)break;
        closest[rec]=mi;
        close[rec]=MAX;
        i=2;
        while(i<n){
            for(j=0;j<n;j++){
                if(closest[j]==-1&&mi+matrix[rec][j]<close[j])close[j]=mi+matrix[rec][j];
            }
        }
    }
}

int main()
{
    memset(close,MAX,sizeof(close));
    memset(closest,-1,sizeof(closest));
    memset(matrix,MAX,sizeof(matrix));
    int i,j;
    cin>>n;
    for(i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        for(j=0;j<b;j++){
            int c,d;
            cin>>c>>d;
            matrix[a][c]=d;
        }
    }
    closest[0]=0;
    djst();
    for(i=0;i<n;i++){
        cout<<i<<" "<<closest[i]<<endl;
    }
    return 0;
}