Go: package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

const NIL = -1

type Node struct {
	id     int
	weight int
}

func init() {
	sc.Split(bufio.ScanWords)
}

type NodeHeap []Node

func (h NodeHeap) Len() int           { return len(h) }
func (h NodeHeap) Less(i, j int) bool { return h[i].weight < h[j].weight }
func (h NodeHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *NodeHeap) Push(x interface{}) {
	*h = append(*h, x.(Node))
}

func (h *NodeHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()

	route := make([][]Node, n)
	weight := make([]int, n)
	for i := 0; i < n; i++ {
		weight[i] = NIL
	}

	for i := 0; i < n; i++ {
		u := scanInt()
		k := scanInt()
		route[i] = make([]Node, k)
		for j := 0; j < k; j++ {
			route[u][j] = Node{id: scanInt(), weight: scanInt()}
		}
	}

	start := Node{id: 0, weight: 0}
	h := &NodeHeap{start}
	heap.Init(h)

	for h.Len() > 0 {
		node := heap.Pop(h).(Node)
		if weight[node.id] != NIL {
			continue
		}
		weight[node.id] = node.weight

		for _, nextNode := range route[node.id] {
			if weight[nextNode.id] != NIL {
				continue
			}
			nextNode.weight += node.weight
			heap.Push(h, nextNode)
		}
	}

	for i, w := range weight {
		fmt.Println(i, w)
	}
}

C++: #define RangeFor(i,n) for(int i=0; i<n; ++i)
#define RvRngFor(i,n) for(int i=n-1; i>=0; --i)

#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#include <numeric>

using std::vector;
using std::cin;
using std::priority_queue;
using std::pair;
using std::make_pair;


vector<int> sssp(vector<vector<pair<int, int> > > c, int start_node = 0){
    int n = c.size();
    priority_queue<pair<int, int>, vector<pair<int,int> >, std::greater<pair<int, int>> > pq;
    vector<int> temp_dist(n, 100000000);
    pq.push(make_pair(0, start_node));

    for(;!pq.empty();pq.pop()){
        auto t = pq.top();
        auto d = t.first;
        auto u = t.second;


        if(d < temp_dist[u]){
            temp_dist[u] = d;
            auto k = c[u].size();
            RangeFor(j, k) {
                pq.push(make_pair(d + c[u][j].second, c[u][j].first));
            }
        }
    }

    return temp_dist;
}

int main(){
    int n; cin >> n;
    vector<vector< pair<int,int> > > c(n);
    RangeFor(i, n) {
        int u;
        cin >> u;
        int k;
        cin >> k;
        c[u] = vector<pair<int, int> >(k);
        RangeFor(j, k) {
            int v;
            cin >> v;
            int d;
            cin >> d;
            c[u][j] = make_pair(v, d);
        }
    }

//    RangeFor(i, n){
//        RangeFor(j, c[i].size()){
//            std::cout << c[i][j].first << ' ' << c[i][j].second;
//        }
//        std::cout << std::endl;
//    }
    
    auto res = sssp(c);
    RangeFor(i, n){
        std::cout << i << ' ' << res[i] << std::endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,i,j;
    cin>>n;
    vector<bool> used(n,false);
    vector<int> dist(n,99999999);
    vector<vector<pair<int,int>>> v(n);
    for(i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        for(j=0;j<b;j++){
            int to,cost;
            cin>>to>>cost;
            v[i].emplace_back(to,cost);
        }
    }
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> q;
    q.push(make_pair(0,0));
    dist[0]=0;
    while(!q.empty()){
        pair<int,int> e;
        e=q.top();q.pop();
        if(used[e.second]) continue;
        used[e.second]=true;
        dist[e.second]=min(dist[e.second],e.first);
        for(auto p:v[e.second]){
            if(!used[p.first]){
                q.push(make_pair(dist[e.second]+p.second,p.first));
            }
        }
    }
    for(i=0;i<n;i++){
        cout<<i<<' '<<dist[i]<<endl;
    }
}

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

#define INF INT_MAX

#define MAX 10000
vector<vector<pair<int, int>>> adj_list(MAX);

void dijkstra(int start_node, int node_size){
    vector<int> visited(node_size, 0);
    vector<int> cost_table(node_size, INF);

    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
    
    visited.at(start_node) = 1;
    cost_table.at(start_node) = 0;
    //queueの初期化 startノードに隣接するノードとそのコストをpush
    // cout << "queue pushed : ";
    int i = 0;
    while(adj_list.at(start_node).at(i).first != -1){
        pair<int, int> x = make_pair(adj_list.at(start_node).at(i).second, adj_list.at(start_node).at(i).first);
        q.push(x);
        // cout << x.first << " " << x.second << "  ";
        cost_table.at(x.second) = x.first;
        i++;
    }
    // cout << endl;

    // cout << "cost_table ====" << endl;
    // rep(i, node_size) cout << i << " " << cost_table.at(i) << endl;
    // cout << endl;


    while(q.size() != 1){
        pair<int, int> Nnode = q.top(); q.pop();
        int nearestNode = Nnode.second;

        visited.at(nearestNode) = 1;

        int i = 0;

        while(adj_list.at(nearestNode).at(i).first != -1){
            int v = adj_list.at(nearestNode).at(i).first; // 構築中の木に隣接するノードvと、追加したノード(nearestNode)からのコストc
            int c = adj_list.at(nearestNode).at(i).second;// 

            // cout << "nearest node : " << nearestNode << " " << v << " " << c << endl;

            if(visited.at(v) == 1){
                // cout << "old" << endl;
                i++;
                continue;
            }else{
                // cout << "new : cost_table " << cost_table.at(v) << " " <<  cost_table.at(nearestNode) << endl;

                if(cost_table.at(v) > cost_table.at(nearestNode) + c){
                    cost_table.at(v) = cost_table.at(nearestNode) + c;
                    q.push(make_pair(cost_table.at(v), v));
                    // cout << "queue pushed : cost " << cost_table.at(v) << " node " << v << endl; 
                }
            }
            i++;
        }
    }

    rep(i, node_size){
        cout << i << " " << cost_table.at(i) << endl;
    }
}



int main(){
    int n; cin >> n;

    //　隣接リストの作成
    rep(i, n){
        int from, k; cin >> from >> k;

        rep(j, k){
            int to, weight; cin >> to >> weight;
            adj_list.at(from).push_back(make_pair(to, weight));
        }
    }

    //番兵の挿入
    rep(i, n){
        adj_list.at(i).push_back(make_pair(-1, -1));
    }

    // cout << endl;
    // rep(i, n){
    //     int j = 0;
    //     while(adj_list.at(i).at(j).first != -1){
    //         cout << adj_list.at(i).at(j).first << " " << adj_list.at(i).at(j).second << " ";
    //         j++;
    //     }
    //     cout << endl;
    // }

    dijkstra(0, n);

}