Go: package main

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

type Item struct {
	value    int // The value of the item; arbitrary.
	priority int // The priority of the item in the queue.
	// The index is needed by update and is maintained by the heap.Interface methods.
	index int // The index of the item in the heap.
}
type PriorityQueue []*Item

func (pq PriorityQueue) Len() int { return len(pq) }
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 = i
	pq[j].index = j
}
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
}

type Q struct {
	pq *PriorityQueue
	ds map[int]int // It has always same value as pq. For random access.
}

func newQ() *Q {
	pq := new(PriorityQueue)
	heap.Init(pq)
	return &Q{
		pq: pq,
		ds: make(map[int]int),
	}
}
func (q *Q) pop() (u, d int) {
	item := heap.Pop(q.pq).(*Item)
	delete(q.ds, item.value)
	return item.value, item.priority
}
func (q *Q) get(u int) (int, bool) { // returns d
	d, ok := q.ds[u]
	return d, ok
}
func (q *Q) set(u, d int) {
	q.ds[u] = d
	for _, item := range *q.pq {
		if item.value != u {
			continue
		}

		item.priority = d
		heap.Fix(q.pq, item.index)
		return
	}
	heap.Push(q.pq, &Item{
		priority: d,
		value:    u,
	})
}
func (q *Q) len() int {
	return len(q.ds)
}

func main() {
	r := bufio.NewReader(os.Stdin)

	var n int
	fmt.Fscan(r, &n)
	cs := make([]map[int]int, n) // []v_i -> c_i
	for h := 0; h < n; h++ {
		var u, k int
		fmt.Fscan(r, &u, &k)
		m := make(map[int]int)
		for i := 0; i < k; i++ {
			var v, c int
			fmt.Fscan(r, &v, &c)
			m[v] = c
		}

		cs[u] = m
	}

	q := newQ()
	q.set(0, 0)
	visited := make(map[int]struct{})
	out := make([]int, n)

	for q.len() > 0 {
		u, d := q.pop()
		for uu, c := range cs[u] {
			// Consider the connection between u and uu.
			if _, ok := visited[uu]; ok {
				continue
			}
			dd := d + c
			if d, ok := q.get(uu); !ok || d > dd {
				q.set(uu, dd)
			}
		}

		out[u] = d
		visited[u] = struct{}{}
	}

	for u, d := range out {
		fmt.Println(u, d)
	}
}

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

const int MAX = 10010;
const int INF = INT_MAX;

int n;
int dist[MAX];
typedef pair<int, int> VC;
typedef pair<int, int> VD;
vector< vector<VC> > G;

void dijkstra(int s)
{
  priority_queue<VD, vector<VD>, function<bool(VD, VD)>> que(
    [](VD a, VD b) { return a.second >= b.second; }
  );

  dist[s] = 0;
  que.push(make_pair(s, dist[s]));
  while (!que.empty()) {
    VD vd= que.top(); que.pop();
    int u = vd.first, d = vd.second;
    for (int i = 0; i < G[u].size(); i++) {
      int v = G[u][i].first, c = G[u][i].second;
      if (dist[v] > d + c) {
        dist[v] = d + c;
        que.push(make_pair(v, dist[v]));
      }
    }
  }
}

int main()
{
  cin >> n;

  fill(dist, dist+n, INF);
  G = vector< vector<VC> >(n);

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

  dijkstra(0);

  for (int i = 0; i < n; i++)
    cout << i << " " << dist[i] << endl;

  return EXIT_SUCCESS;
}

C++: #include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#define P pair<int, int>

using namespace std;
const int MAX = 1<<30;

int main(){
  int n, d[10009];
  vector<P> G[10009];
  queue<int> Q;
  cin >> n;
  for(int i=0;i<n;i++){
    int u, k, v, c;
    cin >>u >> k;
    for(int j=0;j<k;j++){
      cin >> v >> c;
      G[u].push_back(P(v, c));
    }
    d[i] = MAX;
  }
  d[0] = 0;
  Q.push(0);
  while(!Q.empty()){
    int cur = Q.front();Q.pop();
    for(int i=0;i<G[cur].size();i++){
      int next = G[cur][i].first, weight = G[cur][i].second;
      if(weight + d[cur]< d[next]){
        d[next] = weight + d[cur];
        Q.push(next);
      }
    }
  }
  for(int i=0;i<n;i++)cout << i << ' ' << d[i] << endl;
}

C++: //
// Created by yuu on 2019-06-20.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>

using namespace std;

#define MAX 10010
#define INF 1<<20

vector<pair<int, int>> adj[MAX];
int N;

void dijkstra(int start){
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> PQ;
    int d[MAX];
    int check[MAX];
    for (int i = 0; i < N; ++i) {
        d[i] = INF;
        check[i] = -1;
    }

    d[0] = 0;
    check[0] = 0;
    PQ.push(make_pair(0, start));

    while(!PQ.empty()) {
        pair<int, int> f = PQ.top();
        PQ.pop();
        int u = f.second;
        check[u] = 1;

        //　接続先が小さい
        if (d[u] < f.first)continue;

        for (int i = 0; i < adj[u].size(); ++i) {
            int v = adj[u][i].first;
            if (check[v] == 1)continue;

            if (d[v] > d[u] + adj[u][i].second) {
                d[v] = d[u] + adj[u][i].second;
                PQ.push(make_pair(d[v], v));
                check[v] = 0;
            }
        }

    }

    for (int i = 0; i < N; ++i) {
        cout<<i<<" "<< (d[i] == INF? -1 : d[i])<<endl;
    }
}

int main(void){
    int k, u, v, c;
    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(0);






    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
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 BR printf("\n")
#define INF 2000000000

class edge{
public:
    int toid;
    int norm;
    int dist;
    edge(int toid,int norm,int dist){
        this -> toid = toid;
        this -> norm = norm;
        this -> dist = dist;
    }
    bool operator < (const edge &E) const {
        return dist < E.dist;
    }
    bool operator > (const edge &E) const {
        return dist > E.dist;
    }
};

vector<edge> V[10000];
int d[10000];
int count_P = 0;
priority_queue<edge,vector<edge>,greater<edge> > PQ;

void Dijksra(int i,int dist,int n){
    PQ.pop();
    d[i] = dist;
    count_P++;
    if(count_P == n) return;
    
    REP1(k,V[i].size()){
        if (d[V[i][k].toid] == INF && V[i][k].dist > dist + V[i][k].norm){
            V[i][k].dist = dist + V[i][k].norm;
            PQ.push(V[i][k]);
        }
    }
    
    while (d[PQ.top().toid] != INF) PQ.pop();
    if (!PQ.empty()) Dijksra(PQ.top().toid,PQ.top().dist,n);
}

int main(){
    INT(N);
    REP1(i,N) d[i] = INF;
    REP1(i,N){
        int from,n;
        scanf("%d %d",&from,&n);
        REP1(j,n){
            int toid,norm;
            scanf("%d %d",&toid,&norm);
            edge E = edge(toid,norm,INF);
            V[i].push_back(E);
        }
    }
    
    PQ.push(edge(0,0,0));
    Dijksra(PQ.top().toid,0,N);
    
    REP1(i,N){
        printf("%d %d\n",i,d[i]);
    }
    
    return 0;
}