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++: #define RangeFor(i,n) for(int i=0; i<n; ++i)
#define RvRngFor(i,n) for(int i=n-1; i>=0; --i)

#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#include <limits>

using std::vector;
using std::cin;
using std::priority_queue;
using std::pair;
using std::make_pair;


vector<int> sssp(vector<vector<pair<int, int> > > c, int start_node = 0){
    int n = c.size();
    priority_queue<pair<int, int>, vector<pair<int,int> >, std::greater<pair<int, int>> > pq;
    vector<int> temp_dist(n, std::numeric_limits<int>::max());
    pq.push(make_pair(0, start_node));

    for(;!pq.empty();){
        auto t = pq.top(); pq.pop();
        auto d = t.first;
        auto u = t.second;


        if(d < temp_dist[u]){
            temp_dist[u] = d;
            auto k = c[u].size();
            RangeFor(j, k) {
                pq.push(make_pair(d + c[u][j].second, c[u][j].first));
            }
        }
    }

    return temp_dist;
}

int main(){
    int n; cin >> n;
    vector<vector< pair<int,int> > > c(n);
    RangeFor(_, n) {
        int u;
        cin >> u;
        int k;
        cin >> k;
        c[u] = vector<pair<int, int> >(k);
        RangeFor(j, k) {
            int v;
            cin >> v;
            int d;
            cin >> d;
            c[u][j] = make_pair(v, d);
        }
    }

//    RangeFor(i, n){
//        RangeFor(j, c[i].size()){
//            std::cout << c[i][j].first << ' ' << c[i][j].second;
//        }
//        std::cout << std::endl;
//    }

    auto res = sssp(c);
    RangeFor(i, n){
        std::cout << i << ' ' << res[i] << std::endl;
    }
    return 0;
}

C++: #include <iostream>
#include <queue>
#include <vector>
using namespace std;
    int d[10001];
    vector<int> G[500000],w[500000];
void DUK(int n){
    queue<int> q;
    int color[100000];
    for(int i=0;i<n;i++){
        d[i]=100000000;
        color[i]=0;
    }
    d[0]=0;
    q.push(0);
    color[0]=1;
    while(q.size()!=0){
        int u=q.front();
        q.pop();
        color[u]=0;
        for(int i=0;i<G[u].size();i++){
            int v=G[u][i];
            if(d[v]>d[u]+w[u][i]){
                d[v]=d[u]+w[u][i];
                if(color[v]==0){
                    q.push(v);
                    //color[v]=1;
                }
            }
        }
    }
}
int main(){
    int n,v,k,c,u;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>u>>k;
        for(int j=0;j<k;j++){
            cin>>v>>c;
            G[u].push_back(v);
            w[u].push_back(c);
        }
    }
    DUK(n);
    for(int i=0;i<n;i++){
        cout<<i<<" "<<d[i]<<endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct edge{int from, to; ll cost;};

map<ll, ll> d;
priority_queue< Pll, vector<Pll>, greater<Pll> > que;
map<ll, vector<Pll> > edges;

void dijkstra(ll start){
    d[start] = 0;
    que.push(Pll(0, start));

    while(!que.empty()){
        Pll v = que.top(); que.pop();
        if(d.find(v.second) != d.end() && d[v.second] < v.first) continue;
        for(Pll e: edges[v.second]){
            if(d.find(e.first) == d.end() || d[e.first] > d[v.second] + e.second){
                d[e.first] = d[v.second] + e.second;
                que.push(Pll(d[e.first], e.first));
            }
        }
    }
}

int main(){
    std::ios::sync_with_stdio(0); cin.tie(0);
    int n;
    ll u, k, c, v;
    cin >> n;
    rep(n){
        cin >> u >> k;
        repp(j, k){
            cin >> v >> c;
            edges[u].emplace_back(v, c);
        }
    }

    dijkstra(0);
    repp(u, n) cout << u << " " << d[u] << endl;

}

C++: #include<iostream>
using namespace std;
#include<queue>
#include<vector>
#include<string>
#include<string.h>
#include<algorithm>
bool b[2003];

#define REP(i, a) for(int i=0;i<a;i++)
	int N=(1<<20);
int main()
{
	pair<int,int> f;
	vector < pair<int,int> > A[10001];
	priority_queue < pair < int,int > > PQ;
	int min,b,a,k,m,n ,e,p[101],d[101],u,v; //u ?????????v????????¨
	bool color[10001];

	cin>>n;
	REP(i, n) {
		cin>>u>>k;
		REP(i, k) {
			cin>>a>>b;
			if(b==-1) b=N;
			A[u].push_back(make_pair(a,b));
		}
		color[i]=0;
		d[i]=N;
	}
	a=0;
	d[0]=0;
	PQ.push(make_pair(0,0));
	while(!PQ.empty()){
		f=PQ.top();
		PQ.pop();
		u=f.second;
		color[u]=1;
		REP(i,A[u].size()){
			v=A[u][i].first;
			if(color[v]==1){
			continue;
			}
				if(d[v]>A[u][i].second+d[u]){
					d[v]=A[u][i].second+d[u];
					PQ.push(make_pair(d[v]*-1,v));
				}
		}
	}
	REP(i,n){
		cout<<i<<" "<<(d[i] == N ? -1 : d[i])<<endl;
	
	}
	return 0;
}