Go: package main

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

const (
	white int = iota
	gray
	black
)

type node struct {
	id     int
	parent int
	edge   []int
	weight []int
	color  int
}

type graph struct {
	nodes    []node
	distance []int
}

var infty = 1 << 32
var null = -1

func constructgraph() *graph {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)

	g := &graph{make([]node, n), make([]int, n)}

	for i := 0; i < n; i++ {
		id := nextInt(sc)
		edges := nextInt(sc)
		n := node{}
		n.id = id
		n.edge = make([]int, edges)
		n.weight = make([]int, edges)
		n.color = white
		for j := 0; j < edges; j++ {
			to := nextInt(sc)
			w := nextInt(sc)
			n.edge[j] = to
			n.weight[j] = w
		}
		g.nodes[id] = n
	}
	return g
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func (g *graph) preparedijkstra(s int) {
	for i := 0; i < len(g.nodes); i++ {
		g.nodes[i].color = white
		g.nodes[i].parent = null
		g.distance[i] = infty
	}
	g.distance[s] = 0
}

func (g *graph) dijkstra(s int) []int {
	g.preparedijkstra(s)

	for {
		var u int
		mincost := infty
		for i, d := range g.distance {
			if g.nodes[i].color != black && mincost > d {
				mincost = d
				u = i
			}
		}

		if mincost == infty {
			break
		}

		g.nodes[u].color = black

		for i, e := range g.nodes[u].edge {
			if g.nodes[e].color != black {
				if g.distance[e] > g.distance[u]+g.nodes[u].weight[i] {
					g.distance[e] = g.distance[u] + g.nodes[u].weight[i]
					g.nodes[e].parent = u
					g.nodes[e].color = gray
				}
			}
		}
	}
	return g.distance
}

func printShortestPath(d []int) {
	for i, v := range d {
		fmt.Printf("%d %d\n", i, v)
	}
}

func main() {
	g := constructgraph()
	d := g.dijkstra(0)
	printShortestPath(d)
}

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;
}