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<unordered_set>
#define N 105
#define UNDEFINED -1
static const int INF = (1<<21);

int n;
int u, k, v, c;
int G[N][N];
int distance[N], hasVisited[N];


void dijkstra(int s) {
    int minv;
    distance[s] = 0;
    while(true) {
        minv = INF;
        int u = UNDEFINED;
        for (int i = 0; i < n; ++i) {
            if(minv > distance[i] && hasVisited[i] != 1) {
                u = i;
                minv = distance[i];
            }
        }
        if(u == UNDEFINED) break;
        hasVisited[u] = 1;
        for (int v = 0; v < n; ++v) {
            if(distance[v] > distance[u] + G[u][v]) {
                distance[v] = distance[u] + G[u][v];
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        printf("%i %i\n", i, distance[i]);
    }
}

int main() {
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            G[i][j] = INF;
        }
        distance[i] = INF;
        hasVisited[i] = 0;
    }

    std::cin >> n;
    for (int i = 0; i < n; ++i) {
        std::cin >> u >> k;
        for (int j = 0; j < k; ++j) {
                std::cin >> v >> c;
                G[u][v] = c;
            }
        }

    dijkstra(0);

    return 0;
}

C++: #include <iostream>
#include <vector>

using namespace std;

int n;
vector<int> g[100];
vector<int> w[100];
int d[100];
char color[100];

void dijkstra() {
    d[0] = 0;
    color[0] = 'b';

    for (int k = 1; k < n; ++k) {
        int next;
        int mine = INT_MAX;
        for (int i = 0; i < n; ++i) {
            if (color[i] == 'b') {
                for (int j = 0; j < g[i].size(); ++j) {
                    if (d[i] + w[i].at(j) <= d[g[i].at(j)] && color[g[i].at(j)] == 'w') {
                        d[g[i].at(j)] = d[i] + w[i].at(j);
                        if (d[g[i].at(j)] <= mine) {
                            next = g[i].at(j);
                            mine = d[next];
                        }
                    }
                }
            }
        }
        color[next] = 'b';
        d[next] = mine;
    }
}

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int u;
        int k;
        cin >> u >> k;
        int v, c;
        for (int j = 0; j < k; ++j) {
            cin >> v >> c;
            g[u].push_back(v);
            w[u].push_back(c);
        }
    }
    for (int m = 0; m < n; ++m) {
        color[m] = 'w';
        d[m] = INT_MAX;
    }

    dijkstra();

    for (int l = 0; l < n; ++l) {
        cout << l << " " << d[l] << endl;
    }

    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;

const int INF = 0xfffffff;
const int MAX = 10000;

struct Edge {
	bool operator < (const Edge& e)const {
		return c > e.c;
	}
	int v;
	int c;
};

int main() {
	int n;
	vector<Edge> graph[MAX];
	priority_queue<Edge> q;
	int table[MAX];
	bool check[MAX];

	cin >> n;
	for (int i = 0; i < n; i++) {
		table[i] = INF;
		check[i] = false;
	}

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

	int u = 0;
	table[0] = 0;
	while (true) {
		check[u] = true;

		for (int i = 0; i < graph[u].size(); i++) {
			int v = graph[u][i].v;
			int c = graph[u][i].c;
			if (table[v] > c + table[u]) {
				table[v] = c + table[u];
				Edge e;
				e.v = v;
				e.c = table[v];
				q.push(e);
			}
		}
		if (check[q.top().v])break;
		u = q.top().v; q.pop();
	}

	for (int i = 0; i < n; i++) {
		cout << i << " " << table[i] << endl;
	}

	return 0;
}

C++: #include <iostream>
#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;
}