Go: package main

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

//make priority queue
type Item struct {
	id       int
	priority int // this state is priority and distans from start
	index    int
}

type PriorityQueue []*Item

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

// we want the ascending-priority-queue.
// So we use less than here.
func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].priority < pq[j].priority
}

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

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	item.index = -1 //for safety
	*pq = old[0 : n-1]
	return item
}

func (pq *PriorityQueue) update(dist int, id int) {
	for _, i := range *pq {
		if i.id == id {
			if i.priority > dist {
				i.priority = dist
			}
		}
	}
}

// the main code
func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

func dikstra(dist *[][]int, n int) *[]int {
	// preparate priority queue
	inf := 1 << 30
	pq := make(PriorityQueue, n)
	shortests := make([]int, n)
	for i := 0; i < n; i++ {
		pq[i] = &Item{
			id:       i,
			priority: inf,
			index:    i,
		}

		shortests[i] = inf
	}
	pq[0].priority = 0
	shortests[0] = 0
	heap.Init(&pq)

	for pq.Len() > 0 {
		item := heap.Pop(&pq).(*Item)
		shortests[item.id] = item.priority
		for id, d := range (*dist)[item.id] {
			if d != -1 {
				pq.update(item.priority+d, id)
			}
		}
		heap.Init(&pq)
	}
	return &shortests
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	// init
	n := nextInt(sc)
	dist := make([][]int, n)
	for i := 0; i < n; i++ {
		dist[i] = make([]int, n)
		for j := 0; j < n; j++ {
			dist[i][j] = -1
		}
	}

	// std Input
	for i := 0; i < n; i++ {
		u := nextInt(sc)
		k := nextInt(sc)
		for j := 0; j < k; j++ {
			v, c := nextInt(sc), nextInt(sc)
			dist[u][v] = c
		}
	}

	shortests := dikstra(&dist, n)
	for i, d := range *shortests {
		fmt.Printf("%d %d\n", i, d)
	}
}

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