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 <stdio.h>
#include <vector>
#include <algorithm>


using namespace std;

struct Info{
	Info(){
		to=0;
		weight = 0;
	}
	Info(short arg_to,int arg_weight){
		to = arg_to;
		weight = arg_weight;
	}
	short to;
	int weight;
};

class InfoPQ{
public:
	InfoPQ(){
		array = new Info[10000];
		n = 0;
	}
	void push(Info arg_info){
		array[n] = arg_info;
		int tmp = n;
		while(tmp != 0 && array[tmp].weight < array[(tmp-1)/2].weight){
			std::swap(array[tmp], array[(tmp-1)/2]);
			tmp = (tmp-1)/2;
		}
		n++;
	}

	bool isEmpty(){
		return n == 0;
	}

	Info pop(){
		Info ret = array[0];
		n--;
		std::swap(array[0],array[n]);
		int tmp = 0;
		while(2*tmp+1 <= n-1){
			if(2*tmp+2 <= n-1){
				if(array[2*tmp+2].weight < array[tmp].weight && array[2*tmp+2].weight <= array[2*tmp+1].weight){
					std::swap(array[2*tmp+2],array[tmp]);
					tmp = 2*tmp+2;
				}else if(array[2*tmp+1].weight < array[tmp].weight && array[2*tmp+1].weight <= array[2*tmp+2].weight){
					std::swap(array[2*tmp+1],array[tmp]);
					tmp = 2*tmp+1;
				}else{
					break;
				}
			}else{
				if(array[tmp].weight > array[2*tmp+1].weight){
					std::swap(array[tmp],array[2*tmp+1]);
					tmp = 2*tmp+1;
				}else{
					break;
				}
			}
		}
		return ret;
	}

private:
	Info* array;
	int n;
};



int main(){
	int n,count=0,tmp,left_node,right_node,dist,t_to_i;
	scanf("%d",&n);
	vector<Info> V[n];
	InfoPQ A,B;

	Info catcher,tmp_catcher;

	int P[n],zero_dist[n];

	for(int i=0;i<n;i++){
		P[i]=0;
		zero_dist[i] = 10000001;
	}
	zero_dist[0] = 0;
	P[0]=1;

	for(int i=0;i<n;i++){
		scanf("%d %d",&left_node,&tmp);
		if(left_node == 0){
			for(int k=0;k<tmp;k++){
				scanf("%d %d",&right_node,&dist);
				zero_dist[right_node] = dist;
			}
		}else{
			for(int k=0;k<tmp;k++){
				scanf("%d %d",&right_node,&dist);
				V[left_node].push_back(Info(right_node,dist));
			}
		}
	}

	for(short k=1;k<n;k++){
		A.push(Info(k,zero_dist[k]));
	}


	while(count<n-1){
		if(count%2==0){
			catcher = A.pop();
			P[catcher.to]=1;
			count++;

			while(!A.isEmpty()){
				tmp_catcher = A.pop();
				t_to_i = 10000001;
				for(int k=0;k<V[catcher.to].size();k++){
					if(V[catcher.to][k].to == tmp_catcher.to){
						t_to_i = V[catcher.to][k].weight;
						break;
					}
				}
				if(tmp_catcher.weight > catcher.weight+t_to_i){
					tmp_catcher.weight=catcher.weight+t_to_i;
					zero_dist[tmp_catcher.to] = catcher.weight+t_to_i;
				}
				B.push(tmp_catcher);
			}
		}else{
			catcher = B.pop();
			P[catcher.to]=1;
			count++;

			while(!B.isEmpty()){
				tmp_catcher = B.pop();
				t_to_i = 10000001;
				for(int k=0;k<V[catcher.to].size();k++){
					if(V[catcher.to][k].to == tmp_catcher.to){
						t_to_i = V[catcher.to][k].weight;
						break;
					}
				}
				if(tmp_catcher.weight > catcher.weight+t_to_i){
					tmp_catcher.weight=catcher.weight+t_to_i;
					zero_dist[tmp_catcher.to] = catcher.weight+t_to_i;
				}
				A.push(tmp_catcher);
			}
		}
	}

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

    return 0;
}

C++: #include <iostream>
#include <climits>
#include <vector>
using namespace std;
typedef unsigned short ushort;
typedef vector <int> vi;

class blanch{
	public:
		bool visited;
		int distance;
		ushort from;
		ushort to;
};
typedef vector <blanch> vb;
typedef vector <vb> vvb;

int make_graph(vvb &graph, vb &nodes){

	int n=nodes.size();
	for (ushort i=0; i<n; i++){
		nodes[i].visited = false;
		nodes[i].distance = INT_MAX;
	}

	for (ushort i=0; i<n; i++){
		int i2, n2;
		cin>>i2;
		cin>>n2;

		blanch tmp;
		tmp.visited = false;
		tmp.from = i2;

		for (ushort j=0; j<n2; j++){
			cin>>tmp.to;
			cin>>tmp.distance;
			graph[i2].push_back(tmp);
		}
	}
	return 0;
}

int Shortest_Path(vvb &graph, vb &nodes){

	int p1=0;
	nodes[p1].distance = 0;

	int p2;
	while (p1 != -1){
		nodes[p1].visited=true;
		for (ushort i = 0; i < graph[p1].size(); i++){
			blanch tmp = graph[p1][i];
			p2=tmp.to;
			if (!nodes[p2].visited){
				int tmp2 = tmp.distance + nodes[p1].distance;
				if (tmp2 < nodes[p2].distance){
					tmp.distance = tmp2;
					nodes[p2] = tmp;
				}
			}
		}

		p1 = -1;
		int tmp = INT_MAX;
		for (ushort i=0; i<graph.size(); i++){
			if (!nodes[i].visited && nodes[i].distance<tmp){
				p1 = i;
				tmp = nodes[i].distance;
			}
		}
	}
	return 0;
}

int resultout(vb &nodes){
	for (ushort i=0; i<nodes.size(); i++){
		cout<<i<<" "<<nodes[i].distance<<endl;
	}
	return 0;
}

int main(void){

	int n;
	cin>>n;
	vvb G(n, vb());
	vb nodes(n);

	make_graph(G, nodes);

	Shortest_Path(G, nodes);

	resultout(nodes);
	G.clear();
	nodes.clear();

	return 0;
}