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

C++: #include <iostream>
#include <cstdio>
#include <set>
#include <vector>
#include <algorithm>
#include <cstring>
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(true)
	{
		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()
{
	scanf("%d",&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++)
	{
		scanf("%d%d",&u,&k);
		for(int j=0;j<k;j++)
		{
			scanf("%d%d",&v,&c);
			M[u][v]=c;
		}
	}
	dijkstra();
}

C++: #include <iostream>
#include <cstdio>
#pragma warning(disable:4996)
using namespace std;
const int maxn = 100 + 10;
const int maxv = 10000 + 10;
const int INF = 1 << 21;
int n;
int E;
typedef struct{
	int from, to, cost;
}Edge;

Edge e[maxv];
int d[maxn];
void bellman_ford(int s){
	fill(d, d + n, INF);
	d[s] = 0;
	while (true)	{
		bool bUpdate = false;
		for (int i = 0; i<E; i++)	{
			Edge es = e[i];
			if (d[es.from] != INF&&d[es.to]>d[es.from] + es.cost)		{
				d[es.to] = d[es.from] + es.cost;
				bUpdate = true;
			}
		}
		if (!bUpdate) break;
	}
	for (int i = 0; i<n; i++) printf("%d %d\n", i, d[i]);
}

int main(){
	scanf("%d", &n);
	int id, c;
	E = 0;
	for (int i = 0; i<n; i++){
		scanf("%d%d", &id, &c);
		while (c--){
			scanf("%d%d", &e[E].to, &e[E].cost);
			e[E].from = id;
			E++;
		}
	}
	bellman_ford(0);
	return 0;
}

C++: /*宣言*/
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<string.h>
#include<string>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
int main()
{
	int n, u, k, w[101][101], v, c;
	int d[101], kas[101] = { 0 }, K;
	cin >> n;
	memset(d, 0x7f, sizeof(d));
	memset(w, 0x7f, sizeof(w));
	rep(i, n)
	{
		cin >> u >> k;
		rep(j, k)
		{
			cin >> v >> c;
			w[u][v] = c;
		}
	}
	d[0]=0;
	int p[101];
	int Min,Min1;
	Min = 0;
	Min1 = 0x7f;
	kas[0] = 1;
	rep(j, n)
	{
		rep(i, n)
		{
			if (d[i] > d[Min] + w[Min][i])
			{
				d[i] = d[Min] + w[Min][i];
				p[i] = Min;
			}
			if (Min1 > d[i] && kas[i] == 0)
			{
				Min1 = d[i];
				K = i;
			}
		}
		kas[K] = 1;
		Min = K;
		Min1 = 0x7f;
	}
	rep(i, n)
	{
		cout << i <<' '<< d[i] << endl;
	}
	return 0;
}