Go: package main

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

const MAX = 100
const INFTY = math.MaxInt64
const WHITE = 0
const GRAY = 1
const BLACK = 2

var n int
var M [MAX][MAX]int

func dijkstra() {
	var minv int
	var d [MAX]int
	var color [MAX]int

	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 && M[u][v] != INFTY {
				if d[v] > d[u]+M[u][v] {
					d[v] = d[u] + M[u][v]
					color[v] = GRAY
				}
			}
		}

	}
	for i := 0; i < n; i++ {
		fmt.Printf("%v %v\n", i, d[i])
	}
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ = strconv.Atoi(sc.Text())

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			M[i][j] = INFTY
		}
	}

	for i := 0; i < n; i++ {
		sc.Scan()
		f, _ := 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())
			M[f][v] = c
		}
	}
	dijkstra()
}

C++: #include <iostream>
#include <string>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int MAX_N = 110;
int cost[MAX_N][MAX_N], d[MAX_N];
bool used[MAX_N];
void dijkstra(int n)
{
    for(int i = 0; i <= n; i++) { d[i] = INF; used[i] = false; }
    d[0] = 0;
    while(true)
    {
        int v = -1;
        for(int u = 0; u < n; u++)
        {
            if(not used[u] && (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] + cost[v][u]);
    }
    for(int i = 0; i < n; i++) cout << i << " " << d[i] << endl;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++) cost[i][j] = INF;
    }
    for(int i = 0; i < n; i++)
    {
        int u, k; cin >> u >> k;
        for(int i = 0; i < k; i++)
        {
            int v, c; cin >> v >> c;
            cost[u][v] = c;
        }
    }
    dijkstra(n);
    return 0;
}

C++: #include<iostream>
#include<vector>
#define MAX 1000000
using namespace std;
static const int N = 100;
int A[N][N],d[N],p[N],color[N]={0};
void algo(int);
void print(int);
int main(void){
    int n,u,k,v,c;
    cin >> n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            A[i][j] = -1;
        }
    }
    for(int i=0;i<n;i++){
        cin >> u >> k;
        if(k!=0){
            for(int j=1;j<=k;j++){
                cin >> v >> c;
                A[u][v] = c;
            }
        }
    }
    for(int i=0;i<n;i++){
        d[i] = MAX;
        p[i] = 0;
    }
    d[0] = 0;
    algo(n);
    print(n);
    return 0;
}
void algo(int n){
    vector<int> S;
    while(S.size()!=n){
        int min = MAX,u =-1;
        for(int i=0;i<n;i++){
            if(min>d[i] && color[i]!=1){
                min= d[i];
                u= i;
            }
        }
        color[u] = 1;
        S.push_back(u);
        for(int v=0;v<n;v++){
            if(d[u]+A[u][v]<d[v] && A[u][v]!=-1){
                d[v] = d[u] + A[u][v];
                p[v] = u;
            }
        }
    }
}
void print(int n){
    for(int i=0;i<n;i++){
        cout << i << ' ' << d[i] << endl;
    }
}

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

#define rep(i, n) for (int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;

const int INF = 1 << 21;
const int MAX = 103;
const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;
int n, G[MAX][MAX];

void dijkstra() {
  int minv;
  int d[MAX], color[MAX];

  fill((int*)d, (int*)(d+MAX), INF);
  memset(color, WHITE, sizeof(color));

  d[0] = 0;
  color[0] = GRAY;
  while (true) {
    minv = INF;
    int u = -1;
    rep(i,n) {
      if (minv > d[i] && color[i] != BLACK) {
	u = i;
	minv = d[i];
      }
    }
    if (u == -1) break;
    color[u] = BLACK;
    rep(v,n) {
      if (color[v] != BLACK && G[u][v] != INF) {
	if (d[v] > d[u] + G[u][v]) {
	  d[v] = d[u] + G[u][v];
	  color[v] = GRAY;
	}
      }
    }
  }

  rep(i,n) {
    cout << i << ' ' << (d[i] == INF ? -1 : d[i]) << endl;
  }
}

int main() {
  cin >> n;
  rep(i,n) {
    fill((int*)G[i], (int*)(G[i]+n), INF);
  }
  
  int u, k, v, c;
  rep(i,n) {
    cin >> u >> k;
    rep(j,k) {
      cin >> v >> c;
      G[i][v] = c;
    }
  }

  dijkstra();
  return 0;
}

C++: #include<stdio.h>
#define N 100
#define INFTY (1<<21)
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define NON -1

void dijkstra();

int M[N][N],d[N];
int n;

int main(){
  int i,j,u,k,v;
  
  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++) M[i][j]=INFTY;
  }

  
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      scanf("%d",&M[u][v]);
    }
  }

  dijkstra();
  
  for(i=0;i<n;i++){
    printf("%d %d\n",i,d[i]);
  }
  
  return 0;
}



void dijkstra(){
  int u,min;
  int i;
  int color[N];

  //初期化
  for(i=0;i<n;i++){
    d[i]=INFTY;
    color[i]=WHITE;
  }
  
  d[0]=0;
  

  while(1){
    min=INFTY;
    u=NON;
    //進路決め
    for(i=0;i<n;i++){
      if(min>d[i] && color[i]!=BLACK){
        u=i;
        min=d[i];
      }
    }
    if(u==NON) break;
    color[u]=BLACK;
    //次の節点の設定
    for(i=0;i<n;i++){
      if(color[i]!=BLACK && M[u][i]!=INFTY)
      if(d[i]>M[u][i]+d[u]){
        d[i]=M[u][i]+d[u];
        color[i]=GRAY;
      }
    }
  }

}

C++: #include <iostream>

using namespace std;
static const int MAX=100;
static const int INFTY= (1<<21);
int M[MAX][MAX]; //?????\??????
int d[MAX]; //?????????????????¬
bool visited[MAX]; //???????¢??????????

void dijkstra(int n)
{
    int min;
    //init
    for(int i=0;i<n;i++)
    {
        visited[i]=false;
        d[i]=INFTY;
    }
    //select node 0
    d[0]=0;
    while(true)
    {
        min=INFTY;
        int min_point=-1;
        for(int i=0;i<n;i++)  //?????????????????????????????\??¶???
        {
            if(min>d[i]&&visited[i]==false)
            {
                min_point=i;
                min=d[i];
            }
        }
        if(min_point==-1) break;  //??????????????°????????????????????????

        visited[min_point]=true;
        //update
        for(int i=0;i<n;i++)
        {
            if(visited[i]==false&&M[min_point][i]!=INFTY)
                if(d[min_point]+M[min_point][i]<d[i])
                    d[i]=d[min_point]+M[min_point][i];
        }
    }
    //print
    for(int i=0;i<n;i++)
        cout<<i<<' '<<(d[i]==INFTY?-1:d[i])<<endl;
}
int main()
{
    int n;
    cin>>n;
    //init
    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++)
    {
        int j;
        cin>>j;
        int nodes_num;
        cin>>nodes_num;
        for(int k=0;k<nodes_num;k++)
        {
            int v,d;
            cin>>v>>d;
            M[j][v]=d;
        }
    }
    dijkstra(n);
}