Go: // ダイクストラのアルゴリズム
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
	"strings"
)

type color int

const (
	white color = iota // 未訪問
	mst                // MSTとして確定
)

// 頂点
type node struct {
	num       int         // 頂点の番号
	weights   map[int]int // 重みMAP
	parent    *node       // MSTへの重み最小の親
	distFromS int         // 始点からの距離
	color     color
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	n := eGetInt(scanner)

	nodes := make([]*node, n)
	for i := 0; i < n; i++ {
		weights := eAtoi((strings.Fields(eGetline(scanner))))
		v := &node{weights[0], make(map[int]int, weights[1]), nil, math.MaxInt32, white}
		for j := 0; j < weights[1]; j++ {
			k := weights[j*2+2] // 相手の頂点名
			w := weights[j*2+3] // 重み
			v.weights[k] = w
		}
		nodes[i] = v
	}

	// 初回はnode[0]がMSTに入るように
	nodes[0].distFromS = 0

	for { // 全部チェックするまで

		// どの頂点を新たにMSTに取り込むか

		var minNode *node
		min := math.MaxInt32
		for _, v := range nodes {
			if v.color == mst {
				continue
			}
			if v.distFromS < min {
				min = v.distFromS
				minNode = v
			}
		}
		if minNode == nil {
			// すべて完了している.
			break
		}

		// MSTに追加する頂点決定
		minNode.color = mst

		// fmt.Printf(">[%v]\n", minNode)
		// MSTに属していない頂点それぞれについて,Startからの最小の重みの距離を更新
		for i, v := range nodes {
			if v.color == mst {
				continue
			}
			w, ok := minNode.weights[i]
			if !ok {
				// minNodeと接してない
				continue
			}

			if minNode.distFromS+w < v.distFromS {
				// minNode経由の距離がもっとも重みが少ないので親を変更
				v.distFromS = minNode.distFromS + w
				v.parent = minNode
				// fmt.Printf("[%v %v]\n", v, minNode)
			}
		}
		// fmt.Printf("<\n")
	}

	for i, v := range nodes {
		fmt.Printf("%d %d\n", i, v.distFromS)
	}
}

func eGetInt(scanner *bufio.Scanner) int {
	t := eAtoi(strings.Fields(eGetline(scanner)))
	return t[0]
}

func eGetline(p *bufio.Scanner) string {
	if !p.Scan() {
		if err := p.Err(); err != nil {
			log.Fatal(err.Error())
		}
		return ""
	}
	return p.Text()
}

func eAtoi(s []string) []int {
	ints := make([]int, len(s))
	var err error
	for i, e := range s {
		ints[i], err = strconv.Atoi(e)
		if err != nil {
			log.Fatal(err.Error())
		}
	}
	return ints
}

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

#define MAX_VERTEX 100
#define INF 1000000

int vertex_num; // ???????????°
int d[MAX_VERTEX][MAX_VERTEX];  // ???????????¢???d[?§????][??????]??§?§??????????????????????????????¢?????¨???

void Input() {
  cin >> vertex_num;

  // (a1) ??\???????????¶??§?????????
  // d?????¨???INF?????????????§??????¨????????????????????´???0
  for (int i = 0; i < vertex_num; i++){
	  for (int j = 0; j < vertex_num; j++){
		  if (j == i){
			  d[i][j] = 0;
		  }else{
			  d[i][j] = INF;
		  }
	  }
  }


  for (int i = 0; i < vertex_num; i++) {
    int vertex, out;
    cin >> vertex >> out;
    for(int j = 0; j < out; j++) {
      int to, c;
      cin >> to >> c;
      d[vertex][to] = c;
    }
  }
}

void WarshallFloyd() {
	for (int k = 0; k < vertex_num; k++){
		for (int i = 0; i < vertex_num; i++){
			for (int j = 0; j < vertex_num; j++){
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
}

void Output() {
  for(int i = 0; i < vertex_num; i++) {
    cout << i << " " << d[0][i] << endl;
  }
}

int main() {

  Input();
  WarshallFloyd();
  Output();

  return 0;
}

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

#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
int INF = (1<<21);

void dijkstra(void);

int n;
int M[MAX][MAX];

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

void dijkstra(){
  int minV;
  int d[MAX],color[MAX];
  int u,v;
  int i;
  for(i = 0; i < n; i++){
    //d[i] = INFINITY;
    d[i] = INF;
    color[i] = WHITE;
  }
  d[0] = 0;
  color[0] = GRAY;
  while(1){
    //minV = INFINITY;
    minV = INF;
    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 && M[u][v] != INFINITY){
      if(color[v] != BLACK && M[u][v] != INF){
        if(d[v] > d[u] + M[u][v]){
          d[v] = d[u] + M[u][v];
          color[v] = GRAY;
        }
      }
    }
    }
    for(i = 0; i < n; i++){
      //cout << i << " " << (d[i] == INFINITY ? -1 : d[i]) << endl;
      cout << i << " " << (d[i] == INF ? -1 : d[i]) << endl;
    }
  }

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
const int INF=1000000000;
int n,d[100];
int G[100][100];
void dijkstra(int s){
    fill(d,d+n,INF);
    bool used[n]={false};
    d[s]=0;
    while(true){
	int v=-1;
	for(int u=0;u<n;u++){
	    if(used[u]) continue;
	    if(v==-1||d[u]<d[v]) v=u;
	}
	if(v==-1) break;
	used[v]=true;
	
	for(int u=0;u<n;u++){
	    d[u]=min(d[u],d[v]+G[v][u]);
	}
    }
}
int main(){
    cin>>n;
    fill(G[0],G[n],INF);
    for(int i=0;i<n;i++){
	int u,k;
	cin>>u>>k;
	for(int j=0;j<k;j++){
	    int v,c;
	    cin>>v>>c;
	    G[u][v]=c;
	}
    }
    dijkstra(0);
    for(int i=0;i<n;i++){
	cout<<i<<' '<<d[i]<<endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
struct Graph{
  using seen_t=size_t;
  const seen_t NO=1e9;
  vector<seen_t> seen;
  using ver_t=size_t;
  using edge_t=pair<ver_t,seen_t>;
  vector<vector<edge_t>> edge;
  vector<ver_t> prev;
  Graph(size_t n): seen(n,NO), edge(n), prev(n,0) {}
  void search(ver_t v0){
    seen[v0]=0;
    // deque<ver_t> que(1,v0); // dfs,bfs
    priority_queue<pair<seen_t,ver_t>> que; que.push(make_pair(seen[v0],v0)); // dijkstra
    while(!que.empty()){
      // ver_t curv=que.back(); que.pop_back(); // dfs
      // ver_t curv=que.front(); que.pop_front(); // bfs
      ver_t curv=que.top().second; que.pop(); // dijkstra
      for(const auto& nextv:edge[curv]){
        seen_t alt=seen[curv]+nextv.second;
        if(seen[nextv.first]>alt){
          seen[nextv.first]=alt;
          prev[nextv.first]=curv;
          // que.push_back(nextv); // dfs,bfs
          que.push(make_pair(seen[nextv.first],nextv.first)); // dijkstra
        }
      }
    }
  }
};
ostream& operator<<(ostream& os, const Graph& x){
  for(size_t i=0; i<x.edge.size(); ++i){
    cout<<(i)<<' '<<x.seen[i]<<'\n';
  }
  return os;
}
int32_t main(){
  size_t n; cin>>n;
  Graph graph(n);
  size_t u,k,v,c;
  for(size_t i=0; i<n; ++i){
    cin>>u>>k;
    graph.edge[u].resize(k);
    for(size_t i=0; i<k; ++i){
      cin>>v>>c; graph.edge[u][i]=make_pair(v,c);
    }
  }
  graph.search(0);
  cout<<graph;
}

C++: #include<iostream>
#include<algorithm>

using namespace std;

#define NIL -1
#define INF 10000001

struct node{
  int key = INF;
};

node grf[100];
int hv[100][100], n;

void search(){
    for(int i=0;i<n;++i){
        for(int j=0;j<n;++j){
            if(hv[i][j] == NIL){
                continue;
            }
            if(grf[i].key + hv[i][j] < grf[j].key){
                grf[j].key = grf[i].key + hv[i][j];
            }
        }
    }
    return;
}

int main(){
    for(int i=0;i<100;++i){
        for(int j=0;j<100;++j){
            hv[i][j] = NIL;
        }
    }
    
    int p, token, vtal=0;
    cin >> n;
    
    for(int i=0;i<n;++i){
        cin >> p;
        cin >> p;
        vtal += p;
        for(int j=0;j<p;++j){
            cin >> token;
            cin >> hv[i][token];
        }
    }
    
    
    grf[0].key = 0;
    for(int i=0;i<vtal;++i){
        search();
    }
    
    
    for(int i=0;i<n;++i){
        cout << i << " " << grf[i].key << endl;
    }
    
    return 0;
}