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への重み最小の親
	distFromS int         // 始点からの距離
	color     color
}

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, math.MaxInt32, 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].distFromS = 0

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

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

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

		// MSTに追加する頂点決定
		minNode.color = mst

		// fmt.Printf(">[%v]\n", minNode)
		// MSTに属していない頂点それぞれについて,Startからの最小の重みの距離を更新
		for i, v := range nodes {
			if v.color == mst {
				continue
			}
			w, ok := minNode.weights[i]
			if !ok {
				// minNodeと接してない
				continue
			}

			if minNode.distFromS+w < v.distFromS {
				// minNode経由の距離がもっとも重みが少ないので親を変更
				v.distFromS = minNode.distFromS + w
				v.parent = minNode
				// fmt.Printf("[%v %v]\n", v, minNode)
			}
		}
		// fmt.Printf("<\n")
	}

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

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<stdio.h>
#include<stdlib.h>
#include<limits.h>
struct node {
        int id;
        int weight;
        struct node *next;
};
struct node **list;
int *dist, *prev, *heap, *heap_index, heapsize;
void Insert(int, int, int);
void downheap(int);
void upheap(int);
void PQ_Init(int);
void DijkstraPQ(int, int);
main()
{
        int i, j, n, u, k, v, c;
        scanf("%d", &n);
        list = (struct node**)malloc(sizeof(struct node*) * n);
        for (i = 0; i < n; i++) {
                dist = (int*)malloc(sizeof(int) * n);
                prev = (int*)malloc(sizeof(int) * n);
                list[i] = NULL;
        }
        for (i = 0; i < n; i++) {
                scanf("%d%d", &u, &k);
                for (j = 0; j < k; j++) {
                        scanf("%d%d", &v, &c);
                        Insert(u, v, c);
                }
        }
        DijkstraPQ(0, n);
        for (i = 0; i < n; i++) {
                struct node *p, *q;
                printf("%d %d\n", i, dist[i]);
                for (q = list[i], p = q->next; p != NULL; q = p, p = p->next) {
                        q->next = p->next;
                        free(p);
                }
                if (list[i] != NULL) {
                        free(list[i]);
                }
        }
        free(list);
        free(dist);
        free(prev);
        free(heap);
        free(heap_index);
}
void Insert(int a, int b, int weight)
{
        struct node *p = (struct node*)malloc(sizeof(struct node));
        p->id = b;
        p->weight = weight;
        p->next = list[a];
        list[a] = p;
        p = (struct node*)malloc(sizeof(struct node));
    p->id = a;
    p->weight = weight;
        p->next = list[b];
    list[b] = p;
}
void downheap(int k)
{
        int j, v = heap[k];
        while (k < heapsize / 2) {
                j = 2 * k + 1;
                if (j < heapsize - 1 && dist[heap[j]] > dist[heap[j + 1]]) j++;
                if (dist[v] <= dist[heap[j]]) break;
                heap[k] = heap[j];
                heap_index[heap[j]] = k;
                k = j;
        }
        heap[k] = v;
        heap_index[v] = k;
}
void upheap(int j)
{
        int k, v = heap[j];
        while (j > 0) {
                k = (j + 1) / 2 - 1;
                if (dist[v] >= dist[heap[k]]) break;
                heap[j] = heap[k];
                heap_index[heap[k]] = j;
                j = k;
        }
        heap[j] = v;
        heap_index[v] = j;
}
void PQ_Init(int size)
{
        int i;
        heapsize = size;
        heap = (int*)malloc(sizeof(int) * size);
        heap_index = (int*)malloc(sizeof(int) * size);
        for (i = 0; i < size; i++) {
                heap[i] = i;
                heap_index[i] = i;
        }
        for (i = size / 2 - 1; i >= 0; i--) {
                downheap(i);
        }
}
void DijkstraPQ(int p, int size)
{
        int i;
        for (i = 0; i < size; i++) {
                dist[i] = INT_MAX;
                prev[i] = -1;
        }
        dist[p] = 0;
        PQ_Init(size);
        while (heapsize > 0) {
                struct node *n;
                int u = heap[0];
                heap[0] = heap[heapsize - 1];
                heap_index[heap[size - 1]] = 0;
                heapsize--;
                downheap(0);
                for (n = list[u]; n != NULL; n = n->next) {
                        int w = n->weight, newlen = dist[u] + w;
                        if (newlen < dist[n->id]) {
                                dist[n->id] = newlen;
                                prev[n->id] = u;
                                upheap(heap_index[n->id]);
                        }
                }
        }
}

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

using namespace std;

#define Vi vector<int>
#define FOR(i,s,e) for (int i=s; i<e; i++)
#define ITER(v) v.begin(), v.end()

constexpr int N_MAX = 100;

int weight[N_MAX][N_MAX];
int dis[N_MAX];

void set_shortest_distance(const int n) {
    bool ismember[n] = {false};

    int newmember = 0;
    dis[newmember] = 0;
    ismember[newmember] = true;

    FOR(t,0,n-1) {
        FOR(i,0,n) {
            if (weight[newmember][i] < 0) { continue; }
            if (ismember[i]) { continue; }
            const int d = dis[newmember] + weight[newmember][i];
            if (dis[i] < 0 || d < dis[i]) {
                dis[i] = d;
            }
        }
        int min_i = -1, min_d = -1;
        FOR(i,0,n) {
            if (dis[i] < 0) { continue; }
            if (ismember[i]) { continue; }
            if (min_d < 0 || dis[i] < min_d) {
                min_i = i;
                min_d = dis[i];
            }
        }
        newmember = min_i;
        ismember[newmember] = true;
        //cout << "#" << min_i << " " << min_d << endl;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    FOR(i,0,n) {
        dis[i] = -1;
        FOR(j,0,n) {
            weight[i][j] = -1;
        }
    }

    int u, k, v, c;
    FOR(i,0,n) {
        cin >> u >> k;
        FOR(j,0,k) {
            cin >> v >> c;
            weight[u][v] = c;
        }
    }

    set_shortest_distance(n);

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

    return 0;
}