Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

const T = 10000000

var n int
var A [101][101]int

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func Shortestsearch() {
	var Minimum int
	var d, color [100]int
	var u int

	for i := 0; i < n; i++ {
		d[i] = T
		color[i] = 0
	}

	d[0] = 0
	color[0] = 1

	for {
		Minimum = T
		u = -1
		for i := 0; i < n; i++ {
			if Minimum > d[i] && color[i] != 2 {
				u = i
				Minimum = d[i]
			}
		}
		if u == -1 {
			break
		}
		color[u] = 2
		for j := 0; j < n; j++ {
			if color[j] != 2 && A[u][j] != T {
				if d[j] > d[u]+A[u][j] {
					d[j] = d[u] + A[u][j]
					color[j] = 1
				}
			}
		}
	}
	for i := 0; i < n; i++ {
		fmt.Printf("%d %d\n", i, d[i])
	}
}
func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			A[i][j] = T
		}
	}
	for i := 0; i < n; i++ {
		u := nextInt()
		k := nextInt()
		for j := 0; j < k; j++ {
			v := nextInt()
			c := nextInt()
			A[u][v] = c
		}
	}
	Shortestsearch()
}

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

#define INF (1<<21)

int vis[101],M[101][101],d[101],p[101],n;

void dijkstra(){
    int minv,i,j,v;
    for( i = 1; i < n; i++ ){
        d[i] = INF;
        p[i] = -1;
    }
    while(1){
        minv = INF;
        int u = -1;
        for( i = 0; i < n; i++ ){
            if( minv>d[i] && !vis[i] ){
                minv = d[i];
                u = i;
            }
        }
        if( minv == INF ) break;
        vis[u]  = 1;
        for( v = 0; v < n; v++ ){
            if( !vis[i] && M[u][v]!=INF ){
                if( d[v] > d[u] + M[u][v] ){
                    d[v] = d[u] + M[u][v];
                }
            }
        }
    }
    for( i = 0; i < n ; i++ ){
        cout << i << " " << ( d[i]==INF? -1 : d[i] ) << endl;
    }
}

int main(){
    cin >> n;
    int i,j,k,u,v,du,quan;
    k = n;
    for( i = 0; i < n; i++ ){
        for( j = 0; j < n; j++ ){
            M[i][j] = INF;
        }
    }
    while(k--){
        cin >> u >> du;
        for( i = 0; i < du; i++ ){
            cin >> v >> quan;
            M[u][v] =quan;
        }
    }
    dijkstra();
}

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

// O(ElogE)

// pq<pair> はfirstが大きい順に出てくるのですか？
// s:= 開始ノード  v:= 頂点数  adjlist:= 隣接リスト (first:= コスト   second:= 行先)
vector<int> dijk(int s, int v, vector<vector<pair<int, int> > > adjlist){
    
    priority_queue <pair<int, int> > wait;
    vector<int> result(v, INF);

    //スタート地点を追加
    result[s] = 0;
    wait.push(make_pair(0, s));

    //ダイクストラ本体
    while(!wait.empty()){    //waitが空になるまで

        int nowpoint = wait.top().second;
        int nowcost = -wait.top().first;
        wait.pop();

        if(result[nowpoint] < nowcost) continue;


        //今いる頂点と隣接しているすべての頂点をなめる
        for(int i = 0; i < adjlist[nowpoint].size(); i++){

            int nextpoint = adjlist[nowpoint][i].second;
            int nextcost = nowcost + adjlist[nowpoint][i].first;
            //現時点より安く到達できそうであれば、結果を更新して優先度付きキューに格納
            if(result[nextpoint] > nextcost){
                result[nextpoint] = nextcost;
                wait.push(make_pair(-nextcost, nextpoint));
            }
        }
    }
    
    return result;         //結果列を返す
}

int main(){

    int V; cin >> V;
    vector<vector<pair<int, int> > > adjlist(V);      //first := コスト　second := 行先

    //入力
    for(int i = 0; i < V; i++){
        int gomi; cin >> gomi;
        int k; cin >> k;
        for(int j = 0; j < k; j++){
            int v, c; cin >> v >> c;           // a ,b 間に コスト c の辺がある
            adjlist[i].push_back(make_pair(c, v));
        }     
    }

    vector<int> result(V);
    result = dijk(0, V, adjlist);
    //cout << result[G] << endl;

    for(int i = 0; i < V; i++){
        cout << i << " " << result[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 dijkstra() {
   int minv;
   int color[MAX], d[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) {
  	      	  minv = d[i];
  	      	  u = 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;
	int u, k, c, 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 >> c;
			M[u][v] = c;
		}
	}
	
	dijkstra();
	
	return 0;
}

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

struct edge {
  int from, to, cost;
};


int INF;
vector<vector<edge>> es;
vector<int> dist;

bool bellmanFord (int n, int s) {
  dist[s] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < es[j].size(); k++) {
        edge e_ = es[j][k];
        if (dist[e_.from] != INF && dist[e_.to] > dist[e_.from] + e_.cost) {
          dist[e_.to] = dist[e_.from] + e_.cost;
          // n回目にも更新があるなら、負の閉路が存在する
          if (i == n - 1) {
            return true;
          }
        }
      }
    }
  }
  return false;
}

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

  INF = 2000000;
  es.resize(n);
  dist = vector<int>(n, INF);

  for (int i = 0; i < n; i++) {
    int u, k;
    cin >> u >> k;
    for (int j = 0; j < k; j++) {
      edge e;
      e.from = u;
      cin >> e.to >> e.cost;
      es[i].push_back(e);
    }
  }

  bool flg = bellmanFord(n, 0);
  
  for (int i = 0; i < n; i++) {
    cout << i << " " <<  dist[i] << endl;
  }

  return 0;
}