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

	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 <set>
#include <vector>
#include <queue>
#include <stack>
#include <utility>
#include <algorithm>

using namespace std;

typedef long long signed int ll;

constexpr ll NIL = -20000000000;

class path{
public:
    int from;
    int to;
    int dist;
    path(){
        from = -1;
        to = -1;
        dist = -1;
    }
    path(int from_,int to_,int dist_){
        from = from_;
        to = to_;
        dist = dist_;
    }
    static bool compare(const path& a,const path& b) {
        return a.from < b.from;
    }
    bool operator<(const path& e) const {
        return this->dist < e.dist;
    }
};

int n,u,k,v,c;
vector<path> w;
ll d[10000];

int main() {
    for(int i = 0;i < 10000;i++)d[i] = -NIL;
    cin >> n;
    for(int i = 0;i < n;i++) {
        cin >> u >> k;
        for(int j = 0;j < k;j++) {
            cin >> v >> c;
            w.push_back(path(u,v,c));
        }
    }
    sort(w.begin(),w.end(),path::compare);
    priority_queue<pair<int,int>> q;
    q.push(make_pair(0,0));
    d[0] = 0;
    while(!q.empty()) {
        auto y = q.top();q.pop();
        if(d[y.second] != y.first) continue;
        auto r = lower_bound(w.begin(),w.end(),path(y.second,0,0),path::compare);
        auto l = lower_bound(w.begin(),w.end(),path(y.second+1,0,0),path::compare);
        for(auto itr = r;itr < l;itr++) {
            if(d[itr->to] > d[itr->from] + itr->dist) {
                d[itr->to] = d[itr->from] + itr->dist;
                q.push(make_pair(d[itr->to],itr->to));
            }
        }
    }
    for(int i = 0;i < n;i++){
        cout << i << " " << d[i] << endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;

typedef pair<int, int> P;
const int M = 1000000007;

vector<int> dijkstra(int s, vector<vector<P>> edge) {
    int n = edge.size();
    vector<int> dist(n, M);
    priority_queue<P, vector<P>, greater<P>> q;
    dist[s] = 0;
    q.push(P(0, s));
    while (!q.empty()) {
        P p = q.top();
        q.pop();
        for (auto& e : edge[p.second]) {
            if (dist[e.second] > p.first + e.first) {
                dist[e.second] = p.first + e.first;
                q.push(P(p.first + e.first, e.second));
            }
        }
    }
    return dist;
}


int main() {
    int n;
    cin >> n;
    vector<vector<P>> edge(n);
    for (int i = 0; i < n; ++i) {
        int u, k;
        cin >> u >> k;
        if (i != u) exit(1);
        for (int j = 0; j < k; ++j) {
            int v, c;
            cin >> v >> c;
            edge[i].push_back(P(c, v));
        }
    }
    vector<int> d = dijkstra(0, edge);
    for (int i = 0; i < n; ++i) {
        cout << i << " " << d[i] << "\n";
    }
    return 0;
}

C++: //
//  ALDS1_12_B_SingleSortestPath.cpp
//  AizuOnlineJudge
//
//  Created by jiji on 2018/02/21.
//  Copyright © 2018年 jiji4000. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define MAX 10000
#define INFTY 1<<22
#define WHITE 0
#define GRAY 1
#define BLACK 2

// 重み付き有向グラフの隣接リスト
vector<pair<int,int>> adj[MAX];

void dijkstra(int n){
    priority_queue<pair<int,int>>pq;
    // weight[v]に始点sからvまでの最短コストを保存する
    int weight[MAX];
    // 訪問状態を記録
    int color[MAX];
    // 1.初期化
    for(int i = 0;i < n;++i){
        weight[i] = INFTY;
        color[i] = WHITE;
    }
    
    // 始点
    weight[0] = 0;
    color[0] = GRAY;
    pq.push(make_pair(0,0));
    
    while(!pq.empty()){
        pair<int,int> first = pq.top();
        pq.pop();
        // 頂点
        int u = first.second;
        color[u] = BLACK;
        
        // 最短値を取りだして、最短でなければ飛ばす
        if(weight[u] < first.first * -1) continue;
        
        for(int i = 0;i < adj[u].size();++i){
            int v = adj[u][i].first;
            if(color[v] == BLACK)continue;
            if(weight[v] > weight[u] + adj[u][i].second){
                weight[v] = weight[u] + adj[u][i].second;
                // priority_queueはデフォルトで大きい値を優先するので-にする
                pq.push(make_pair(weight[v] * -1, v));
                color[v] = GRAY;
            }
        }
    }
    
    // 出力
    for(int i = 0;i < n;++i){
        cout << i << " " << ( weight[i] == INFTY ? -1 : weight[i] ) << endl;
    }
}

int main(){
    int n,k,c,u,v;
    cin >> n;
    
    for(int i = 0;i < n;++i){
        cin >> u >> k;
        for(int j = 0;j < k;++j){
            cin >> v >> c;
            adj[u].push_back((make_pair(v,c)));
        }
    }
    dijkstra(n);
    return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <queue>
#define N 10010
#define INF 0x3f3f3f3f
using namespace std;
typedef pair<int, int> ii;
vector<ii> m[N];
int n;
int used[N];
int d[N];
priority_queue<ii, vector<ii>, greater<ii> > td;
void dijk(){
    d[0] = 0;
    used[0] = 1;
    td.push(make_pair(0, 0));
    while(!td.empty()){
        ii temp = td.top(); td.pop();
        if(temp.first == INF) break;
        int du = temp.first;
        int u = temp.second;
        for(int j = 0; j < m[u].size(); j++){
            int v = m[u][j].second;
            if(!used[v] && d[u]+m[u][j].first < d[v]){
                d[v] = d[u] + m[u][j].first;
                td.push(make_pair(d[v], v));
            }
        }
    }
    for(int i = 0; i < n; i++){
        printf("%d %d\n", i, d[i]);
    }
}
int main(){
    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
        d[i] = INF;
        used[i] = 0;
    }
    for(int p = 0; p < n; p++){
        int node, k;
        scanf("%d %d", &node, &k);
        for(int t = 0; t < k; t++){
            int a, b;
            scanf("%d %d", &a, &b);
            m[node].push_back(make_pair(b, a));
        }
    }
    dijk();
    return 0;
}