Go: // ダイクストラのアルゴリズム
package main

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

type color int

const (
	white color = iota // 未訪問
	mst                // MSTとして確定
)

// 頂点
type node struct {
	num     int         // 頂点の番号
	weights map[int]int // 重みMAP
	parent  *node       // MSTへの重み最小の親
	sum     int         // 始点からの距離
	color   color
}

func (p *node) getMinToMst() int {
	if p.parent == nil {
		return math.MaxInt32
	}
	return p.weights[p.parent.num]
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	n := eGetInt(scanner)

	nodes := make([]*node, n)
	for i := 0; i < n; i++ {
		weights := eAtoi((strings.Fields(eGetline(scanner))))
		v := &node{weights[0], make(map[int]int, weights[1]), nil, 0, white}
		for j := 0; j < weights[1]; j++ {
			k := weights[j*2+2] // 相手の頂点名
			w := weights[j*2+3] // 重み
			v.weights[k] = w
		}
		nodes[i] = v
	}

	// 初回はnode[0]がMSTに入るように
	nodes[0].parent = nodes[0]

	for { // 全部チェックするまで

		// どの頂点を新たにMSTに取り込むか

		var minNode *node
		min := math.MaxInt32
		for _, v := range nodes {
			if v.color == mst {
				continue
			}
			if v.getMinToMst() < min {
				min = v.getMinToMst()
				minNode = v
			}
		}
		if minNode == nil {
			// すべて完了している.
			break
		}

		// MSTに追加する頂点決定
		minNode.color = mst
		// 自分の親の合計値と合算する
		minNode.sum = minNode.parent.sum + min

		// MSTに属していない頂点それぞれについて,MSTとの最小の重みの距離を加算
		for _, v := range nodes {
			if v.color == mst {
				continue
			}
			w, ok := v.weights[minNode.num]
			if !ok {
				// minNodeと接してない
				continue
			}

			if w < v.getMinToMst() {
				// minNodeへの距離がもっとも重みが少ないので親を変更
				v.parent = minNode
			}
		}
	}

	for i, v := range nodes {
		fmt.Printf("%d %d\n", i, v.sum)
	}
}

func eGetInt(scanner *bufio.Scanner) int {
	t := eAtoi(strings.Fields(eGetline(scanner)))
	return t[0]
}

func eGetline(p *bufio.Scanner) string {
	if !p.Scan() {
		if err := p.Err(); err != nil {
			log.Fatal(err.Error())
		}
		return ""
	}
	return p.Text()
}

func eAtoi(s []string) []int {
	ints := make([]int, len(s))
	var err error
	for i, e := range s {
		ints[i], err = strconv.Atoi(e)
		if err != nil {
			log.Fatal(err.Error())
		}
	}
	return ints
}

C++: #include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF 9223372036854775807

#define N 100

int G[N][N];
int d[N];

void dijkstra(int s, int n)
{
    int visited[n], p[n];
    for (int i = 0; i < n; i++)
    {
        visited[i] = 0;
        d[i] = INF;
    }
    d[s] = 0;

    while (true)
    {
        int mincost = INF;
        int u = -1;
        for (int i = 0; i < n; i++)
        {
            if (!visited[i] && d[i] < mincost)
            {
                mincost = d[i];
                u = i;
            }
        }

        if (u == -1)
            break;

        visited[u] = 1;
        for (int i = 0; i < n; i++)
        {
            if (G[u][i] != INF && !visited[i])
            {
                if (d[u] + G[u][i] < d[i])
                {
                    d[i] = d[u] + G[u][i];
                    p[i] = u;
                }
            }
        }
    }
}

signed main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            G[i][j] = 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, n);

    for (int i = 0; i < n; i++)
        cout << i << ' ' << d[i] << endl;
}

C++: #include<iostream>
#define INF 1<<21
using namespace std;
static const int N = 101;
int n,A[N][N];
void dikstra(void){
    int d[N],p[N],color[N],minv;
    for(int i=0;i<n;i++){
        d[i] = INF;
        p[i] = -1;
        color[i] = 0;
    }
    d[0] = 0;
    while(1){
        int u =-1;
        minv = INF;
        for(int i=0;i<n;i++){
            if(d[i]<minv && color[i]!=1){
                u = i;
                minv = d[i];
            }
        }
        if(u==-1){
            break;
        }
        color[u] = 1;
        for(int v=0;v<n;v++){
            if(d[u]+ A[u][v] < d[v] && color[v]!=1){
                d[v] = d[u] + A[u][v];
                p[v] = u;
            }
        }
    }
    for(int i=0;i<n;i++){
        cout << i << ' ' << d[i] << endl;
    }
}
int main(void){
    int u,adj,v;
    cin >> n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            A[i][j] = INF;
        }
    }
    for(int i=0;i<n;i++){
        cin >> u >> adj;
        for(int j=0;j<adj;j++){
            cin >> v >> A[u][v];
        }
    }
    dikstra();
    return 0;
}

C++: #include<bits/stdc++.h>

using namespace std;
#define fordebug int hoge;cin>>hoge;
#define DEKAI 1000000007
#define INF (1<<28)
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define floot10 cout<<fixed<<setprecision(10);
#define int long long


signed main(){
	int n;
	cin>>n;
	vector<pair<int,int> > v[200];
	lp(i,n){
		int u,k;
		cin>>u>>k;
		lp(j,k){
			int a,b;
			cin>>a>>b;
			v[u].push_back(make_pair(a,b));
		}
	}
	queue<pair<int,int> > q;
	q.push(make_pair(0,0));
	int memo[200];
	lp(i,200) memo[i]=INF;
	memo[0]=0;
	while(!q.empty()){
		pair<int,int> hoge=q.front();
		q.pop();
		int now=hoge.first;
		int cos=hoge.second;
		lp(i,v[now].size()){
			int next=v[now][i].first;
			int cost=v[now][i].second;
			if(memo[next]>cos+cost){
				 q.push(make_pair(next,cos+cost));
				 memo[next]=cos+cost;
			}
		}
	}
	lp(i,n){
		cout<<i<<" "<<memo[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(s[v[last][i]]!=BLACK && 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 <map>
#include <vector>
#include <cstdio>
using namespace std;
int main(){
	int n=0,N,i,j,k,c;
	scanf("%d",&N);
	vector<map<int,int> >dist(N);
	vector<bool>used(N);
	vector<int>cost(N);
	for(;n<N;n++){
		cost[n]=999999;
		for(scanf("%d%d",&i,&k);k--;dist[i][j]=c)scanf("%d%d",&j,&c);
	}
	for(cost[0]=0;;){ //dijkstra
		int m=999999;
		for(i=0;i<N;i++)if(!used[i]&&m>cost[i])m=cost[i];
		if(m==999999)break;
		for(j=0;j<N;j++)if(m==cost[j]){
			map<int,int>::iterator it=dist[j].begin();
			for(used[j]=1;it!=dist[j].end();it++)if(cost[it->first]>it->second+cost[j])cost[it->first]=it->second+cost[j];
		}
	}
	for(i=0;i<n;i++)printf("%d %d\n",i,cost[i]);
}