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 <vector>
using namespace std;
struct edge {int from, to, cost;};
const long long INF = 1000000000;
void bellman_ford(std::vector<edge> & es, std::vector<int> & d, int E, int V, int s) {
  for(int i=0;i<V;i++) d[i] = INF;
  d[s] = 0;
  while(true) {
    bool update = false;
    for(int i=0;i<E;i++) {
      edge e = es[i];
      if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
        d[e.to] = d[e.from] + e.cost;
        update = true;
      }
    }
    if(!update) break;
  }
}
 
int main() {
  int n;
  cin >> n;
  vector<edge> e;
  for(int i=0;i<n;i++) {
    int u, k;
    cin >> u >> k;
    for(int j=0;j<k;j++) {
      int vi, ci;
      cin >> vi >> ci;
      edge ei = {u, vi, ci};
      e.push_back(ei);
    }
  }
  vector<int> d(n);
  bellman_ford(e, d, e.size(), n, 0);
  for(int i=0;i<n;i++) {
    cout << i << " " << d[i] << endl;
  }

}

C++: #include <iostream>
using namespace std;
#define MAX 100
#define INFTY 1<<22
#define WHITE 0
#define GRAY 1
#define BLACK 2

int gMatrix[MAX][MAX];

void dijkstra(int n){
    // 最小の重みを記録する
    int minV;
    int weight[MAX];
    int color[MAX];
    
    for(int i = 0;i < n;++i){
        weight[i] = INFTY;
        color[i] = WHITE;
    }
    // 始点
    weight[0] = 0;
    color[0] = GRAY;
    
    while(1){
        minV = INFTY;
        // 頂点
        int u = -1;
        for(int i = 0;i < n;++i){
            if(minV > weight[i] && color[i] != BLACK){
                u = i;
                minV = weight[i];
            }
        }
        if(u == -1)break;
        color[u] = BLACK;
        
        for(int v = 0;v < n;++v){
            if(color[v] != BLACK && gMatrix[u][v] != INFTY){
                if(weight[v] > weight[u] + gMatrix[u][v]){
                    weight[v] = weight[u] + gMatrix[u][v];
                    color[v] = GRAY;
                }
            }
        }
    }
    // 出力
    for(int i = 0;i < n;++i){
        cout << i << " " << ( weight[i] == INFTY ? -1 : weight[i] ) << endl;
    }
}

int main(){
    int n;
    cin >> n;
    
    for(int i = 0;i < n;++i){
        for(int j = 0;j < n;++j){
            gMatrix[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;
            gMatrix[u][v] = c;
        }
    }
    dijkstra(n);
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
static const int INFTY = (1 << 21);
static const int BLACK = 1;
static const int Maxn = 110;

int n, M[Maxn][Maxn], p[Maxn], d[Maxn], color[Maxn];
void dijkstra(){
	for(int i = 0; i < n; i++){
		d[i] = INFTY;
		p[i] = -1;
	}
	d[0] = 0;
	while(1){
		int minv = INFTY, u = -1;
		for(int i = 0; i < n; i++){
			if(d[i] < minv && 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] + d[u] < d[v]){
				d[v] = M[u][v] + d[u];
				p[v] = u;
			}
		}
	}
	for(int i = 0; i < n; i++) cout << i << " " << d[i] << endl;
}
int main()
{
	memset(M, -1, sizeof(M));
	int u, k, t, c;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> u >> k;
		while(k--){
			cin >> t >> c;
			M[u][t] = c;
		}
		for(int j = 0; j < n; j++) 
			if(M[u][j] == -1)  M[i][j] = INFTY;
	}	
	/*for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++) cout << M[i][j] << " ";
		cout << "\n";
	}*/
	dijkstra();
	return 0;
}

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

const int MAX = 110;
const int INF = INT_MAX;

int edge[MAX][MAX];
int dist[MAX];

void dijkstra(int s, int n)
{
  queue<int> que;

  dist[s] = 0;
  que.push(s);
  while (!que.empty()) {
    int u = que.front(); que.pop();
    for (int v = 0; v < n; v++) {
      if (edge[u][v] != -1 && (dist[v] == INF || dist[v] > dist[u] + edge[u][v])) {
        dist[v] = dist[u] + edge[u][v];
        que.push(v);
      }
    }
  }
}

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

  memset(edge, -1, sizeof(edge));
  fill(dist, dist+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;
      edge[u][v] = c;
    }
  }

  dijkstra(0, n);

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

  return EXIT_SUCCESS;
}

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++) {
      d[i][j] = i == j ? 0 : 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;
}