Go: package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const INF = 1 << 60

type Edge struct {
	to, cost int
}

type Node struct {
	id, cost int
}

type PQ []Node

func (pq PQ) Len() int           { return len(pq) }
func (pq PQ) Less(i, j int) bool { return pq[i].cost < pq[j].cost }
func (pq PQ) Swap(i, j int)      { pq[i], pq[j] = pq[j], pq[i] }

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

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

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	E := make([][]Edge, N)
	for i := 0; i < N; i++ {
		id, k := sc.nextInt(), sc.nextInt()
		E[id] = make([]Edge, k)
		for j := 0; j < k; j++ {
			to, cost := sc.nextInt(), sc.nextInt()
			E[id][j] = Edge{to, cost}
		}
	}

	d := make([]int, N)
	for i := 0; i < N; i++ {
		d[i] = INF
	}
	done := make([]bool, N)
	pq := &PQ{}
	heap.Init(pq)
	d[0] = 0
	heap.Push(pq, Node{0, 0})
	for pq.Len() > 0 {
		cur := heap.Pop(pq).(Node).id
		if done[cur] {
			continue
		}
		done[cur] = true
		for i := 0; i < len(E[cur]); i++ {
			to, cost := E[cur][i].to, E[cur][i].cost+d[cur]
			if !done[to] && cost < d[to] {
				d[to] = cost
				heap.Push(pq, Node{to, cost})
			}
		}
	}

	for i := 0; i < N; i++ {
		fmt.Fprintln(wtr, i, d[i])
	}
	wtr.Flush()
}

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);

}

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

typedef vector<pair<int, int> > adj;

struct current_cost
{
	int index, cost;
	bool operator < (const current_cost &cur) const
	{
		return cost < cur.cost;
	}
};

current_cost init(int i, int c)
{
	current_cost cur;
	cur.index = i, cur.cost = c;
	return cur;
}

int main()
{
	int i, j, k, n, m, next, cost;
	scanf("%d", &n);
	adj *adlist;
	adlist = new adj [n];

	for(k = 0; k < n; k++){
		scanf("%d %d", &i, &m);
		for(j = 0; j < m; j++){
			scanf("%d %d", &next, &cost);
			adlist[i].push_back(make_pair(next, cost));
		}
	}
	
	int *d;
	d = new int [n];
	d[0] = 0;
	for(i = 1; i < n; i++){
		d[i] = 200000;
	}

	priority_queue<current_cost> C;
	current_cost cur = init(0, 0);
	C.push(cur);

	int size;
	bool *check;
	check = new bool [n];
	for(i = 0; i < n; i++){ check[i] = false; }

	while(!C.empty())
	{
		cur = C.top(); C.pop();
		if(check[cur.index]) continue;
		check[cur.index] = true;

		i = cur.index;
		size = adlist[i].size();
		for(j = 0; j < size; j++){
			k = adlist[i][j].first;
			if(d[i] + adlist[i][j].second < d[k]){
				d[k] = d[i] + adlist[i][j].second;
				C.push(init(k, d[k]));
			}
		}
	};
	for(i = 0; i < n; i++){ printf("%d %d\n", i, d[i]); }

	return 0;
}