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 <iostream>
#include <vector>
#include <queue>
const int inf=1e9;
using namespace std;
int main(){

  int n,now=0;
  priority_queue < pair<int,int>, vector<pair<int,int> >, greater<pair<int,int> > > g[100000];
  cin>>n;
  for(int i=0,u,k,v,c;i<n&&cin>>u>>k;i++) for(int j=0;j<k&&cin>>v>>c;j++) g[u].push(make_pair(c,v));
  int flag[100]={},c[100]={};
  for(int i=1;i<n;i++) c[i]=inf;
  for(int i=0;i<n-1;i++){
    int next=g[now].top().second;
    for(;!g[now].empty();g[now].pop()) if(!flag[g[now].top().second]) c[g[now].top().second]=min(c[g[now].top().second],c[now]+g[now].top().first);
    flag[now]=1;
    now=next;
  }
  for(int i=0;i<n;i++) cout<<i<<" "<<c[i]<<endl;
  return 0;

}

C++: #include <stdio.h>
int a[10000][10000];
int d[10000];
int p[10000];
int q[10000];
int main(){
    int n, i, j, t, u, v,c=0;
    scanf("%d", &n);
    for(i = 0; i < n; i++)
        for(j = 0; j < n; j++){
            a[i][j]=1000000000;
            if(i == j) a[i][j] = 0;
        }
    for(i = 0; i < n; i++) {
        scanf("%d", &j);
        scanf("%d", &c);
        for(j = 0; j < c; j++) {
            scanf("%d %d", &t, &u);
            a[i][t] = u;
        }
        d[i] = 1e9;
        q[i] = 0;
    }
    d[0] = 0;
    c = 0;
    while(c != n) {
        t = 0;
        j = 1000000001;
        for(i = 0; i < n;i++) {
            if(!q[i]&&d[i] < j) {
                t = i;
                j = d[i];
            }
        }
        q[t] = 1;c++;
        for(i = 0; i < n; i++) {
            if(a[t][i] != 1000000000) {
                if(d[i] > d[t] + a[t][i]) {
                    d[i] =  d[t] + a[t][i];
                }
            }
        }
    }
    for(i = 0; i < n; i++) {
        printf("%d %d\n", i, d[i]);
    }
    return 0;
}

C++: #include <iostream>
using ll = long long;
using namespace std;
/* initialize */
int n, u, k, v, c, A[100][100];

void dijkstra(){
    int c[100], d[100], p[100];
    for (int i = 0; i < n; ++i) { c[i] = 0;  d[i] = 100000000;}
    d[0] = 0;
    p[0] = -1;
    int minc;
    while(true){
        minc = INT32_MAX;
        int u = -1;
        for (int i = 0; i < n; ++i) {
            if (c[i] != 2 && d[i] < minc){
                minc = d[i];
                u = i;
            }
        }
        if(u == -1) break;

        c[u] = 2;

        for (int v = 0; v < n; ++v) {
            if (c[v] != 2 && A[u][v] != 100000000){
                if(d[u] + A[u][v] < d[v]){
                    d[v] = d[u] + A[u][v];
                    p[v] = u;
                    c[v] = 1;
                }
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        cout << i << " " << (d[i] == 100000000 ? -1 : d[i]) << "\n";
    }
};
/* main */
int main() {
    cin >> n;
    for (int l = 0; l < n; ++l) {
        for (int i = 0; i < n; ++i) {
            A[l][i] = 100000000;
        }
    }
    for (int i = 0; i < n; ++i) {
        scanf("%d %d", &u, &k);
        for (int j = 0; j < k; ++j) {
            scanf("%d %d", &v, &c);
            A[u][v] = c;
        }
    }
    dijkstra();
    return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
#define MAX_N 100
#define INF 1e9

int cost[MAX_N][MAX_N];
int d[MAX_N];
bool used[MAX_N];
int n, u, k, c, v;

void dijkstra(int s){
  fill(d, d + n, INF);
  fill(used, used + n, false);
  d[s] = 0;

  while(true){
    int v = -1;

    for(int u = 0; u < n; u++){
      if(!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]);
    }
  }
}

int main(void){
  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++){
    cin >> u >> k;
    for(int j = 0; j < k; j++){
      cin >> v >> c;
      cost[u][v] = c;
    }
  }
  dijkstra(0);
  for(int i = 0; i < n; i++){
    cout << i << " " << d[i] << endl;
  }
  return 0;
}