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<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
using namespace std;
#define INT(x) int x; scanf("%d",&x)
#define INPUT(x) scanf("%d",&x)
#define REP1(x,n) for(int x = 0; x < n; x++)
#define REP2(x,s,e) for(int x = s; x <= e; x++)
#define RREP1(x,n) for(int x = n-1; x >= 0; x--)
#define RREP2(x,s,e) for(int x = s; x >= e; x--)
#define BR printf("\n")
#define INF 2000000000
#define INF_LL 9223372036854775806

typedef long long ll;

int G;

ll length[10000];

class edge{
public:
    int fromid;
    int toid;
    int m;
    int len;
    
    edge(int from){
        len = 0;
        fromid = from;
        INPUT(toid);
        INPUT(m);
    }
    
    bool operator < (const edge &e) const {
        return len < e.len;
    }
};

//??§?????????????????????????????????????????§??????????????\?????????
priority_queue<edge> PQ;
vector<vector<edge> > eList;

void dijkstra(int i, ll len){
    if(length[i] != INF_LL) return;
    
    //1.??????????????¢????¢????
    PQ.pop();
    length[i] = len;
    
    //2.?¨??????????????£????????´?
    REP1(k,eList[i].size()){
        if(length[i] != INF_LL){
            eList[i][k].len = -length[i] - eList[i][k].m;
            PQ.push(eList[i][k]);
        }
    }
    
    //3.?¬?????¨??????????????¢?????????????
    while (PQ.size() != 0 && length[PQ.top().toid] != INF_LL) {
        PQ.pop();
    }
    
    //4.?????£????????????
    if (PQ.size() != 0) {
        dijkstra(PQ.top().toid, -PQ.top().len);
    }
}

int main(){
    INPUT(G);
    REP1(i,G){
        vector<edge> list;
        eList.push_back(list);
        length[i] = INF_LL;
        INT(from);
        INT(k);
        REP1(j,k){
            edge e(from);
            eList[i].push_back(e);
        }
    }
    PQ.push(eList[0][0]);
    
    dijkstra(0,0);
    
    REP1(i,G){
        printf("%d %lld\n",i,length[i]);
    }
    
    return 0;
}

C++: #include <stdio.h>
#include <vector>

using namespace std;

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


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

	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(dist,right_node));
			}
		}
	}

	while(count<n-1){

		min=10000001;
		for(int i=1;i<n;i++){
			if(P[i]==0&&zero_dist[i]<min){
				min_index = i;
				min = zero_dist[i];
			}
		}
		t = min_index;
		P[t]=1;
		count++;

		for(int i=1;i<n;i++){
			t_to_i = 10000001;
			for(int k=0;k<V[t].size();k++){
				if(V[t][k].to == i){
					t_to_i = V[t][k].weight;
					break;
				}
			}
			if(zero_dist[i] > zero_dist[t]+t_to_i){
				zero_dist[i]=zero_dist[t]+t_to_i;
			}
		}
	}

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

    return 0;
}

C++: //
//  main.cpp
//
//
//  Created by ???????????? on 2017/10/23.
//  Copyright ?? 2017 ????????????. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <queue>
#include <algorithm>


#define n_max 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INFTY 1<<20

using namespace std;

int n, M[n_max][n_max], color[n_max], d[n_max], p[n_max];

void init(){
    int i, j, id, num, node;
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        for(j = 0; j < n; j++){
            M[i][j] = INFTY;
        }
    }
    
    
    for(i = 0; i < n; i++){
        scanf("%d %d", &id, &num);
        for(j = 0; j < num; j++){
            scanf("%d", &node);
            scanf("%d", &M[id][node]);
        }
        color[i] = WHITE;
        d[i] = INFTY;
    }
}

void dijkstra(){
    //initializing
    d[0] = 0;
    p[0] = -1;
    
    priority_queue<pair<int, int>> PQ;
    
    PQ.push(make_pair(0, 0));
    
    int u;
    while(!PQ.empty()){
        //first weight, second idx
        pair<int, int> f= PQ.top(); PQ.pop();
        u = f.second;
        color[u] = BLACK;
        
        if(d[u] < f.first*(-1)) continue;
        
        for(int v = 0; v < n; v++){
            if((color[v] != BLACK) && (M[u][v] != INFTY)){
                if((d[u] + M[u][v]) < d[v]){
                    d[v] = M[u][v] + d[u];
                    PQ.push(make_pair(d[v]*(-1), v));
                    color[v] = GRAY;
                }
            }
        }
    }
    for(int i = 0; i < n; i++){
        cout<<i<<" "<<d[i]<<endl;
    }
}

int main(int argc, const char * argv[]) {
    init();
    dijkstra();
    return 0;
}