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 <cstdlib>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#include <cmath>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)

#define debug(x) cerr<<#x<<": "<<x<<'\n'

#define fi first
#define se second

#define vi vector<int>
#define pb push_back
#define mp make_pair

#define pcnt __builtin_popcount

typedef long long ll;

const int inf = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int G[110][110] = {};
int d[110] = {};
int main(){
    int n;
    cin >> n;
    memset(G,-1,sizeof(G));
    rep(i,n){
        int t,m;
        cin >> t >> m;
        rep(j,m){
            int a,b;
            cin >> a >> b;
            G[t][a] = b;
        }
    }

    rep(i,n) d[i] = 900010000;
    d[0] = 0;
    while(true){
        bool update = false;
        rep(i,n){
            rep(j,n){
                if(i==j) continue;
                if(G[i][j] != -1 && d[i] + G[i][j] < d[j]){
                    d[j] = d[i]+G[i][j];
                    update = true;
                }
            }
        }
        if(!update) break;
    }

    rep(i,n){
        cout << i << " " << d[i] << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#define MAX 100
#define INF (1<<30)

using namespace std;
enum state{
  BLACK,
  WHITE
};

int main(){
  vector<int> v[MAX];
  vector<int> c[MAX];
  state s[MAX];
  int d[MAX];
  int n; cin>>n;

  for(int i=0;i<n;i++){
    int u; cin>>u;
    int k; cin>>k;
    for(int j=0;j<k;j++){
      int tmp,tmp2; cin>>tmp>>tmp2;
      v[u].push_back(tmp);
      c[u].push_back(tmp2);
    }
  }

  for(int i=0;i<n;i++){
    s[i] = WHITE;
    d[i] = INF;
  }
  s[0]=BLACK;
  d[0]=0;

  vector<int> blacklist;
  blacklist.push_back(0);

  while(1){
    int& last = blacklist.back();
    for(int i = 0;i<v[last].size();i++){
      if(d[v[last][i]]>d[last]+c[last][i]){
        d[v[last][i]]=d[last]+c[last][i];
      }
    }

    int minv=-1;
    for(int b:blacklist){
      for(int i=0;i<v[b].size();i++){
        if(s[v[b][i]]!=BLACK && d[v[b][i]]<d[minv]){
          minv=v[b][i];
        }
      }
    }
    if(minv!=-1){
      s[minv]=BLACK;
      blacklist.push_back(minv);
    }else{
      break;
    }
  }

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

C++: #include<iostream>
#include<cstdio>
#include<climits>
using namespace std;
 
#define N 10000
int n;
 
int g[N][N];
 
int weight[N];
bool us[N];
 
//prim
void prim(){
 
  int v;
  
  weight[0]=0;
   
  while(true){
    v=-1;
    
    for(int i=0;i<n;i++){
      if(us[i]!=true && (v==-1 ||weight[i]<weight[v]))v=i;
    }
 
    if(v==-1)break;
    us[v]=true;
  
 
    for(int i=0;i<n;i++){
      if(weight[i]>(g[v][i]+weight[v])){
 
        weight[i]=(g[v][i]+weight[v]);
        //      cout <<"fsafa"<<endl;
      }
    }
  }
  
}
 
 
int main(){
 
  int u,k1,c,v;
 
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      g[i][j]=9953535;
    }
  }
 
  //load n
  cin >>n;
 
  //load data
  for(int i=0;i<n;i++){
    weight[i]=INT_MAX;
    us[i]=false;
    scanf("%d %d",&u,&k1);
    for(int j=0;j<k1;j++){
      scanf("%d %d",&v,&c);
      g[u][v]=c;
      //    cout <<g[i][j]<<" ";
    }
    //    cout <<endl;
  }
 
 
 
 
  //print
  prim();
 
  for(int i=0;i<n;i++){
    cout <<i<<" "<<weight[i]<<endl;
  }
  return 0;
 
}

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

#define MAX 100
#define BLACK 0
#define GRAY 1
#define WHITE 2
#define INF (1<<30)

int graph[MAX][MAX];
int n;

// プロトタイプ宣言
void dijkstra(int start);
// ここまで

int main(){
	for(int i=0;i<MAX;i++){
		for(int j=0;j<MAX;j++){
			graph[i][j]=INF;
		}
	}

	int from,to,k,weight;		cin>>n;
	for(int i=0;i<n;i++){
		cin>>from>>k;
		for(int j=0;j<k;j++){
			cin>>to>>weight;
			graph[from][to]=weight;
		}
		
	}

	dijkstra(0);

	return 0;
}

//  - - - - - - - - - - - - - - - - - - - --
void dijkstra(int start){
	int color[MAX];
	int d[MAX];
	int p[MAX];
	for(int i=0;i<MAX;i++){
		color[i]=WHITE;
		d[i]=INF;
		p[i]=-1;
	}

	d[start]=0;
	p[start]=-1;

	while(1){
		int from = -1;
		int minCost=INF;
		for(int i=0;i<n;i++){
			if(color[i]!=BLACK && d[i]<minCost){
				minCost=d[i];
				from=i;
			}
		}
		if(from == -1)break;
		
		color[from]=BLACK;

		for(int to=0;to<n;to++){
			if(color[to]!=BLACK && graph[from][to]!=INF){
				if(d[from]+graph[from][to] < d[to]){
					d[to] =d[from]+graph[from][to];
					p[to]=from;
					color[to]=GRAY;
				}
			}
		}
	}

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

C++: #include<cstdio>

const static int MAX = 100;
const static int WHITE = 0;
const static int GRAY = 1;
const static int BLACK = 2;
const static int INFTY = (1<<30);

int M[MAX][MAX];
int color[MAX];
int d[MAX];
int p[MAX];
int n;

void dijkstra()
{
	//初始化
	for(int i=0; i<n; i++)
	{
		color[i] = WHITE;
		d[i] = INFTY;
	}
	int u;
	int mincost;
	d[0] = 0;
	p[0] = -1;

	while(1)
	{
		//选出d[u]最小的点
		mincost = INFTY;
		for(int i=0; i<n; i++)
		{
			if(color[i] != BLACK && mincost > d[i])
			{
				mincost = d[i];
				u = i;
			}
		}
		color[u] = BLACK;

		if(mincost == INFTY) break;

		for(int i=0; i<n; i++)
		{
			if(color[i] != BLACK && M[u][i] < INFTY)
			{
				if(d[u] + M[u][i] < d[i])
				{
					d[i] = d[u] + M[u][i];
					p[i] = u;
					color[i] = GRAY;
				}
			}
		}
	}
}

int main()
{
	scanf("%d", &n);
	for(int i=0; i<n; i++)
	{
		for(int j=0; j<n; j++)
			M[i][j] = INFTY;
	}
	int u,k,v,c;
	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();

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

	return 0;
}