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 <stdio.h>
#include <queue>
#include <vector>
#include <functional>

#define N 100
using namespace std;


class list {
public:
	int cost;
	int node;
	int from;
	list(void) {
		cost = -1;
		node = -1;
		from = -1;
	}
};

bool operator<(const list& y,const list& x) {
	return (y.cost < x.cost);
};
bool operator>(const list& y,const list& x) {
	return (y.cost>x.cost);
};

list m[N][N];
bool visited[N];
int sum = 0;
int dist[N];

int main(void) {
	priority_queue<list, vector<list>, greater<list> > pq;
	int n;
	int now;
	int work;
	int k[N];
	int u;
	scanf("%d", &n);
	for (int i = 0; i<n; i++) {
		visited[i] = false;
		scanf("%d", &u);
		scanf("%d", &k[u]);
		for (int j = 0; j < k[u]; j++) {
			int a, b;
			scanf("%d", &a);
			scanf("%d", &b);
			m[u][j].cost = b;
			m[u][j].node = a;
		}
	}
	now = 0;
	dist[now] = 0;
	while (1) {
		//printf("I'm in %d\n", now);
		visited[now] = true;
		for (int j = 0; j<k[now]; j++) {
				list a;
				a.cost = m[now][j].cost;
				a.node = m[now][j].node;
				a.from=now;
				pq.push(a);
				//printf("I pushed %d %d\n", a.node, a.cost);
		}
		//system("pause");
		list x;
		while (!pq.empty()) {
			if (visited[(pq.top()).node] == false) {
				x = pq.top();
				//printf("I got %d %d %d %d\n", x.node, x.cost,sum,x.from);
				pq.pop();
				now = x.node;
				sum += x.cost;
				dist[now] = dist[x.from]+x.cost;
				break;
			}
			else pq.pop();
		}
		if (x.node == -1)break;
	}
	for (int i = 0; i < n; i++) printf("%d %d\n", i, dist[i]);
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
static const int INFTY = 2000000000;
static const int NIL = -1;
static const int MAX = 10000;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

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

void dijkstra(int a[]){
    priority_queue<pair<int,int> > PQ;
    int color[MAX];
    int d[MAX];
    for(int i=0;i<n;i++){
        d[i] = INFTY;
        color[i] = WHITE;
    }

    d[0] = 0;
    PQ.push(make_pair(0,0));
    color[0] = GRAY;

    while(!PQ.empty()){
        pair<int,int> f = PQ.top(); PQ.pop();
        int u = f.second;
        color[u] = BLACK;
        //????°???????????????????????????????????????§???????????°??????
        if(d[u] < f.first * (-1)) continue;

        for(int j=0;j<adj[u].size();j++){
            int v = adj[u][j].first;
            if(color[v] == BLACK) continue;
            if(d[v] > d[u] + adj[u][j].second){
                d[v] = d[u] + adj[u][j].second;
                //priority_queue???DEFAULT??§??§?????????????????????????????????-1??????????????????
                PQ.push(make_pair(d[v] * (-1),v));
                color[v] = GRAY;
            }
        }
    }

    for(int i=0;i<n;i++) a[i] = d[i];
}

int main(){
    int k,u,v,c;

    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d %d",&u,&k);
        for(int j=0;j<k;j++){
            scanf("%d %d",&v,&c);
            adj[u].push_back(make_pair(v,c));
        }
    }
    int a[MAX];
    dijkstra(a);
    
    for(int i=0;i<n;i++){
            printf("%d %d\n",i,a[i]);
    }

    return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
static const int NMAX = 100;
#define INF (1 << 30)

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> adj[NMAX];

  for (int i = 0; i < n; i++) {
    int id, nn;
    cin >> id >> nn;
    for (int j = 0; j < nn; j++) {
      int to, weight;
      cin >> to >> weight;
      // use negative weights for priority_queue
      adj[id].push_back(make_pair(-weight, to));
    }
  }

  bool visited[n];
  int dist[n];
  for (int i = 0; i<n; i++) {
    visited[i] = false;
    dist[i] = -INF;
  }

  priority_queue<pair<int, int>> distQ;

  // add node 0
  for (int i = 0; i < adj[0].size(); i++) {
    distQ.push(adj[0][i]);
    int weight = adj[0][i].first;
    int id = adj[0][i].second;
    dist[id] = weight;
  }
  visited[0] = true;

  while (!distQ.empty()) {
    // find nearest node
    int minnode = distQ.top().second;
    distQ.pop();

    // add node
    visited[minnode] = true;

    // update dist
    for (int i = 0; i < adj[minnode].size(); i++) {
      int weight = adj[minnode][i].first;
      int id = adj[minnode][i].second;

      if (visited[id] == false) {
        int newWeight = dist[minnode] + weight;
        if (-newWeight < -dist[id]) {
          distQ.push(make_pair(newWeight, id));
          dist[id] = newWeight;
        }
      }
    }
  }

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