Go: package main

import (
	"fmt"
	"container/heap"
)

type Node struct {
	Id int
	Dis int
}

type PriorityQueue []*Node

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].Dis < pq[j].Dis
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *PriorityQueue) Push(x interface{}) {
	*pq = append(*pq, x.(*Node))
}

func (pq *PriorityQueue) Pop() interface{} {
	n := len(*pq)
	pop := (*pq)[n-1]
	*pq = (*pq)[0:n-1]
	return pop
}

func main() {
	var n int
	fmt.Scan(&n)

	g := make([][]int, n)
	c := make([][]int, n)
	pq := make(PriorityQueue, 0, n)
	d := make([]int, n)
	for i := 0; i < n; i++ {
		var u,k int
		fmt.Scan(&u)
		fmt.Scan(&k)
		g[u] = make([]int, k)
		c[u] = make([]int, k)
		for j := 0; j < k; j++ {
			fmt.Scan(&g[u][j])
			fmt.Scan(&c[u][j])
		}

		if u == 0 {
			d[u] = 0
		} else {
			d[u] = 1 << 30
		}
		pq.Push(&Node{u, d[u]})
	}
	heap.Init(&pq)

	for pq.Len() > 0 {
		node := heap.Pop(&pq).(*Node)
		for i := 0; i < len(g[node.Id]); i++ {
			nextId := g[node.Id][i]
			nextDis := node.Dis + c[node.Id][i]
			if nextDis < d[nextId] {
				d[nextId] = nextDis
				heap.Push(&pq, &Node{nextId, nextDis})
			}
		}
	}

	for i := 0; i < n; i++ {
		fmt.Println(i, d[i])
	}
}

C++: // ALDS1_12_B: Single Shortest Path I
#include <iostream>
#include <vector>
#include <algorithm>
#define INF 1000000
#define NIL -1
using graph = std::vector<std::vector<int>>;
bool debug = false;

graph adjacency_matrix;
std::vector<bool> node_stat;
std::vector<int> next_node, minimum_cost;

void dijkstra(int vertex) {
    if (debug) std::cout << "dijkstra(" << vertex << ")\n";
    node_stat.at(vertex) = false;

    for (int i=0; i<adjacency_matrix.at(vertex).size(); i++) {
        int next_vertex = i, edge_weight = adjacency_matrix.at(vertex).at(next_vertex);
        if (edge_weight != -1) {
            int cost_to_next = minimum_cost.at(vertex) + edge_weight;
            if (cost_to_next < minimum_cost.at(next_vertex)) {
                if (debug) std::cout << vertex << " -> " << next_vertex << ": " << cost_to_next << "\n";
                minimum_cost.at(next_vertex) = cost_to_next;
                next_node.at(vertex) = next_vertex;
            }
        }
    }

    int min_weight = INF, next_vertex = NIL;
    for (int i=0; i<minimum_cost.size(); i++) {
        if (minimum_cost.at(i) < min_weight) {
            if (node_stat.at(i)) {
                if (debug) std::cout << "i = " << i << "\n";
                min_weight = minimum_cost.at(i);
                next_vertex = i;
            }   
        }
    }
    if (debug) std::cout << "min_weight = " << min_weight << ", next_vertex = " << next_vertex << "\n";
    if (next_vertex == NIL) {
        return;
    }
    dijkstra(next_vertex);
}

void init() {
    node_stat.assign(node_stat.size(), true);
    next_node.assign(next_node.size(), NIL);
    minimum_cost.assign(minimum_cost.size(), INF);
    minimum_cost.at(0) = 0;
}

int main() {
    int total_node_num; std::cin >> total_node_num;
    
    adjacency_matrix.resize(total_node_num);
    for (int i=0; i<adjacency_matrix.size(); i++) adjacency_matrix.at(i).assign(total_node_num, NIL);
    node_stat.resize(total_node_num);
    next_node.resize(total_node_num);
    minimum_cost.resize(total_node_num);
    
    for (int i=0; i<total_node_num; i++) {
        int vertex_num; std::cin >> vertex_num;
        int outdegree; std::cin >> outdegree;
        for (int j=0; j<outdegree; j++) {
            int next_vertex; std::cin >> next_vertex;
            std::cin >> adjacency_matrix.at(vertex_num).at(next_vertex);
        }
    }
    init();
    dijkstra(0);
    for (int i=0; i<minimum_cost.size(); i++) {
        std::cout << i << " " << minimum_cost.at(i) << "\n";
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

#define MAX 100
#define INFTY (1 << 21)
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[MAX][MAX], d[MAX], color[MAX];

void shortestPath(int s){
    int u, minv;
    //距離を初期化
    for(int i = 0; i < n; i++){
        d[i] = INFTY;
        color[i] = WHITE;
    }

    d[s] = 0;

    while(1){
        int u = -1;
        int minv = INFTY;
        //最も距離が近いものを更新
        for(int i = 0; i < n; i++){
            if(color[i] != BLACK && d[i] < INFTY){
                if(d[i] < minv){
                    u = i;
                    minv = d[i];
                }
            }
        }

        if(u == -1) break;
        color[u] = BLACK;

        for(int v = 0; v < n; v++){
            d[v] = min(d[v], d[u] + M[u][v]);
        }
    }
}

int main(){
    cin >> n;
    //隣接行列を作製

    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            M[i][j] = INFTY;
        }
    }

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

    shortestPath(0);

    rep(i,n){
        cout << i << " " << d[i] << endl;
    }

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define rep(i, n) REP(i, 0, n)
#define REP(i,k,n) for(int i = k; i < n; i++)
#define mmax(start, end) *max_element(start, end)
#define mmin(start, end) *min_element(start, end)
#define argmax max_element
#define argmin min_element
#define push push_back
#define pop pop_back
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef string str;

int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

template<class T = ll> T in() {
    T _in;
    cin >> _in;
    return _in;
}

#define EMAX 10000000

int cost[101][101];

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

    ll n=in();
    ll d[101];

    rep(i, n) {
        rep(j, n) {
            cost[i][j] = EMAX;
        }
        d[i] = EMAX;
    }

    rep(i, n) {
        int u=in<int>(), k=in<int>();
        rep(j, k) {
            int v=in<int>(), c=in<int>();
            cost[u][v] = c;
        }
    }

    // ノード0からの距離を調べる
    d[0] = 0;
    bool flag = true;
    while(flag) {
        flag=false;
        // 移動する方法のある全ノードからの，次のノードへの移動コストを考える
        rep(i, n) {
            if(d[i] != EMAX) {
                rep(j, n) {
                    if(i == j)
                        continue;
                    int next_c = d[i] + cost[i][j];

                    // 更新できる場合更新
                    if(d[j] > next_c) {
                        d[j] = next_c;
                        flag=true;
                    }
                }
            }
        }
    }

    rep(i, n) {
        cout << i << " " << d[i] << endl;
        // rep(j, n) {
        //     cout << cost[i][j] << " ";
        // }
        // cout << endl;
    }
    
    return 0;
}