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++: #include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define FORq(i, m, n) for(int i = m;i <= n;i++)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define PRINTD(n) printf("%d\n",n)
#define DEBUG printf("%s\n","debug")
using namespace std;
//////////////////////////////////////////////////////
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_12_B&lang=jp
struct Vertex {
	// edge information
	vector<int> edges_to; //to vertex number
	vector<int> edges_cost; // edge cost
	
	//for dijkstra
	bool done; //conform or not
	int cost; // now cost
	
	bool operator<(const Vertex& another) const { // priority --> min
        return another.cost < cost; // order(cost)
    }
	
	bool operator==(const Vertex& another) const {
        return another.cost == cost; // order(cost)
    }
};

const int V_MAX = 10003;
struct Vertex v[V_MAX];


int main(){
	priority_queue<Vertex>Q;
	int n; // vertex 0-indexed
	SCD(n);
	REP(i,n){ // 0-indexed
		int u,k;
		SCD2(u,k);
		REP(j,k){
			int nv,c; // to edge , its cost
			SCD2(nv,c);
			v[u].edges_to.push_back(nv);
			v[u].edges_cost.push_back(c);
		}
	}
	
	REP(i,n){
		v[i].done = false;
		v[i].cost = -1;
	}
	
	v[0].cost = 0; //start
	Q.push(v[0]);
	
	while (!Q.empty()){
		Vertex nowV = Q.top(); Q.pop();
		nowV.done = true;
		
		REP(i,nowV.edges_to.size()){
			int nto = nowV.edges_to[i];
			int ncost = nowV.cost + nowV.edges_cost[i];
			if (((v[nto].cost) < 0) or (ncost < v[nto].cost)){  //not visited or required refresh
				v[nto].cost = ncost;
				Q.push(v[nto]);
			
			}
			
		}
	}
	
	REP(i,n){ // output
		printf("%d %d\n",i,v[i].cost);
	}
	
	
}

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

#define NUM 100
#define NIL -1
#define INF 1000000000
#define WHITE 0
#define BLACK 1
int node_num;
vector<tuple<int, int>> G[NUM];
int V[NUM];
int color[NUM];

void init(void){
    scanf("%d", &node_num);

    for(int i = 0; i < node_num; i++){
        int u, k;
        scanf("%d", &u);
        scanf("%d", &k);

        for(int j = 0; j < k; j++){
            int v_, c;
            scanf("%d", &v_);
            scanf("%d", &c);
            G[u].push_back(make_tuple(v_, c));
        }
    }

    for(int i = 0; i < node_num; i++){
        color[i] = WHITE;
        V[i] = INF;
    }
}

void updateAround(int n){
    color[n] = BLACK;
    for(int i = 0; i < G[n].size(); i++){
        V[get<0>(G[n][i])] = min(V[get<0>(G[n][i])], V[n] + get<1>(G[n][i]));
    }

    int min_index = NIL;
    int min_value = INF;
    for(int i = 0; i < node_num; i++){
        if(color[i] == BLACK){
            continue;
        }
        if(V[i] < min_value){
            min_value = V[i];
            min_index = i;
        }
    }
    if(min_index != NIL){
        updateAround(min_index);
    }
}

int main(void){
    init();

    V[0] = 0;
    updateAround(0);

    for(int i = 0; i < node_num; i++){
        printf("%d %d\n", i, V[i]);
    }
}