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 <array>
#include <algorithm>
#include <limits>
#include <cmath>
#include <numeric>
#include <string>

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
#define rep(i, a, b) for(int i = (a); i < (b); ++i )
#define rrep(i, a, b) for(int i = (a); i > (b); --i )
#define REP(i, a, b) for(int i = (a); i <= (b); ++i )
#define RREP(i, a, b) for(int i = (a); i >= (b); --i )
#define llrep(i, a, b) for(ll i = (a); i < (b); ++i )
#define llrrep(i, a, b) for(ll i = (a); i > (b); --i )
#define llREP(i, a, b) for(ll i = (a); i <= (b); ++i )
#define llRREP(i, a, b) for(ll i = (a); i >= (b); --i )
#define ullrep(i, a, b) for(ull i = (a); i < (b); ++i )
#define ullrrep(i, a, b) for(ull i = (a); i > (b); --i )
#define ullREP(i, a, b) for(ull i = (a); i <= (b); ++i )
#define ullRREP(i, a, b) for(ull i = (a); i >= (b); --i )

class UnionFind {
public:
    UnionFind(unsigned long long n) : rank_(n, 0), p_(n, 0) {
        rep(i, 0, n) {
            MakeSet(i);
        }
    }

    void MakeSet(int x) {
        p_[x] = x;
        rank_[x] = 0;
    }

    bool Same(int x, int y) {
        return FindSet(x) == FindSet(y);
    }

    void Link(int x, int y) {
        if (rank_[x] > rank_[y]) {
            p_[y] = x;
        } else {
            p_[x] = y;
            if (rank_[x] == rank_[y]) {
                rank_[y]++;
            }
        }
    }

    void Unite(int x, int y) {
        Link(FindSet(x), FindSet(y));
    }

    int FindSet(int x) {
        if (x != p_[x]) {
            p_[x] = FindSet(p_[x]);
        }
        return p_[x];
    }

private:
    std::vector<int> rank_, p_;
};

int N, Q;

int G[100][100];
int d[100];
int p[100];
int c[100];

int main() {
    cin >> N;
    rep(i, 0, N) {
        rep(j, 0, N) {
            G[i][j] = 10000010;
        }
    }
    rep(i, 0, N) {
        int u, k;
        cin >> u >> k;
        rep(j, 0, k) {
            int t, d;
            cin >> t >> d;
            G[u][t] = d;
        }
    }
    rep(i, 0, N) {
        d[i] = numeric_limits<int>::max();
    }

    d[0] = 0;
    p[0] = 0;
    while (true) {
        int m = -1;
        int min_d = numeric_limits<int>::max();
        rep(i, 0, N) {
            if ((c[i] == 0) && (min_d > d[i])) {
                min_d = d[i];
                m = i;
            }
        }
        if (m < 0) {
            break;
        }
        c[m] = 1;
        rep(i, 0, N) {
            if ((d[m] + G[m][i]) < d[i]) {
                d[i] = d[m] + G[m][i];
                p[i] = m;
            }
        }
    }
    rep(i, 0, N) {
        cout << i << " " << d[i] << endl;
    }
}

C++: #include <stdio.h>
#include <iostream>
#include <queue>
using namespace std;

class Vertice;
class Edge;

class Vertice{
private:
	int id;
	int edge_num;
	int *vertice_id_list;
	Edge **edges;
	bool flag_fixed;
	int distance_min;
public:
	Vertice(int id, int edge_num_max);
	~Vertice(){ delete[] edges, vertice_id_list; }
	int getDistanceMin() const { return distance_min; }
	void addEdge(int vertice_id, Edge *edge);
	void addVertices(Vertice *vertices[]);
	void setDistance(int d);
	void serveDistance();
	void setFlagFixed(){ flag_fixed = true; }
};

class Edge{
private:
	int distance;
	Vertice *vertice;
public:
	Edge(int distance){ this->distance = distance; }
	void addVertice(Vertice *vertice){ this->vertice = vertice; }
	void setDistance(int distance){ vertice->setDistance(distance + this->distance); }
};

struct verticeComp {
	bool operator()(const Vertice *v1, const Vertice *v2)
	{
		return v1->getDistanceMin() > v2->getDistanceMin();
	}
};

priority_queue<Vertice*, vector<Vertice*>, verticeComp> PQ; 

Vertice::Vertice(int id, int edge_num_max)
{
	this->id = id;
	edge_num = 0;
	vertice_id_list = new int[edge_num_max];
	edges = new Edge*[edge_num_max];
	flag_fixed = false;
	distance_min = 1000000;
}

void Vertice::addEdge(int vertice_id, Edge *edge)
{
	edges[edge_num] = edge;
	vertice_id_list[edge_num] = vertice_id;
	edge_num++;
}

void Vertice::addVertices(Vertice *vertices[])
{
	for (int i = 0; i < edge_num; i++) {
		edges[i]->addVertice(vertices[vertice_id_list[i]]);
	}
}

void Vertice::setDistance(int d)
{
	if (flag_fixed) return;
	if (d < distance_min) distance_min = d;
	PQ.push(this);
}

void Vertice::serveDistance()
{
	for (int i = 0; i < edge_num; i++) {
		edges[i]->setDistance(distance_min);
	}
	if (PQ.empty()) return;
	Vertice *fixed_vertice = PQ.top();
	PQ.pop();
	fixed_vertice->setFlagFixed();
	fixed_vertice->serveDistance();
}

int main(void)
{
	Vertice **vertices;

	int n;
	cin >> n;
	vertices = new Vertice*[n];
	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		vertices[u] = new Vertice(u, k);
		for (int j = 0; j < k; j++) {
			int v, c;
			cin >> v >> c;
			vertices[u]->addEdge(v, new Edge(c));
		}
	}

	for (int i = 0; i < n; i++) {
		vertices[i]->addVertices(vertices);
	}

	vertices[0]->setDistance(0);
	vertices[0]->setFlagFixed();
	PQ.pop();
	vertices[0]->serveDistance();

	for (int i = 0; i < n; i++) {
		cout << i << " ";
		cout << vertices[i]->getDistanceMin() << endl;
	}

	return 0;
}