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 <iostream>
#include <vector>
#include <queue>

using ll = long long;
using namespace std;
/* initialize */
int n;
vector<pair<int, int> > adj[10000];

void dijkstra(){
    priority_queue<pair<int,int> > PQ;
    int color[10000];
    int d[10000];
    for (int i = 0; i < n; ++i) {d[i] = INT32_MAX; color[i] = 0;};
    d[0] = 0;
    PQ.push(make_pair(0, 0));
    color[0] = 1;
    while (!PQ.empty()){
        pair<int, int> f = PQ.top(); PQ.pop();
        int u = f.second;
        color[u] = 2;
        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] == 2) continue;
            if (d[v] > d[u] + adj[u][j].second){
                d[v] = d[u] + adj[u][j].second;
                PQ.push(make_pair(d[v]*-1, v));
                color[v] = 1;
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        cout << i << " " << (d[i] == INT32_MAX ? -1 : d[i]) << "\n";
    }
};
/* main */
int main() {
    int k, u, v, c;

    cin >> 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].emplace_back(v,c);
        }
    }
    dijkstra();
    return 0;
}

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

using namespace std;
#define MAX_N (10010)
#define INF (1000000100)
typedef struct {
    int to;
    int w;
} Edge;

vector<Edge> G[MAX_N];
int n;

int dist[MAX_N];
bool arrived[MAX_N];

void dijkstra(int s)
{
    priority_queue< pair<int, int> > PQ;
    for ( int i = 0; i < n; i++ ) {
	dist[i] = INF;
	arrived[i] = false;
    }

    dist[s] = 0;
    PQ.push(make_pair(0, 0));

    while ( !PQ.empty() ) {
	pair<int, int> u = PQ.top(); PQ.pop();
	if ( u.second > dist[u.first] ) continue;
	arrived[u.first] = true;
	
	for ( int i = 0; i < G[u.first].size(); i++ ) {
	    Edge e = G[u.first][i];
	    if ( !arrived[e.to] && dist[e.to] > (dist[u.first] + e.w) ) {
		dist[e.to] = dist[u.first] + e.w;
		PQ.push(make_pair(e.to, dist[e.to]));
	    }
	}
    }

}

int main()
{
    scanf("%d", &n);
    
    for ( int i = 0; i < n; i++ ) {
	int u, k;
	scanf("%d %d", &u, &k);

	for ( int j = 0; j < k; j++ ) {
	    int v, c;
	    Edge e;
	    scanf("%d %d", &v, &c);
	    e.to = v;
	    e.w = c;
	    G[u].push_back(e);
	}
    }

    dijkstra(0);

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

    return 0;
}

C++: #include <iostream>
#include <vector>
#include <queue>

#define INF 1000000000
using namespace std;

struct edge {
    int from;
    int to;
    int w;
};
struct node {
    node() : id {-1}, d {INF}, ns {} {};
    node(int i, vector<edge>& vec) : id {i}, d {INF}, ns {vec} {};
    int id;
    int d;
    vector<edge> ns;
};

struct node_s {
    int id;
    int d;
};

vector<int> dijkstra(node* graph, int n, int st){
    auto ds = vector<int>(n, INF);
    auto comp = [](node_s* x, node_s* y){return x->d > y->d;};
    priority_queue<node_s*, vector<node_s*>, decltype(comp)> que(comp);
    node_s* start = new node_s {graph[st].id, 0};
    que.push(start);
    while(que.size()){
        node_s* n = que.top();
    /    cout << n->id << ' ' << n->d << endl;
        que.pop();
        if(n->d < ds[n->id]){
            ds[n->id] = n->d;
            for(auto e : graph[n->id].ns){
                if(ds[e.to] < INF){
                    continue;
                }
                node_s* next_n = new node_s {graph[e.to].id, ds[n->id] + e.w};
                que.push(next_n);
            }
        }
        delete n;
    }
    return ds;
}

int main(){
    cin.sync_with_stdio(false);
    cout.sync_with_stdio(false);
    int n;
    cin >> n;
    node graph[n];
    for(int i = 0; i < n; ++i){
        int id;
        int m;
        cin >> id >> m;
        auto vec = vector<edge>(m);
        int v, c;
        for(int j = 0; j < m; ++j){
            cin >> v >> c;
            vec[j] = edge {id, v, c};
        }
        graph[id] = node(id, vec);
    }
    auto ds = dijkstra(graph, n, 0);
    for(int i = 0; i < n; ++i){
        cout << i << ' ' << ds[i] << endl;
    }
}

C++: #ifdef LOCAL_BUILD
#include "pch.h"
#define DLOG(msg) cout << "#" << __LINE__ << ":" << msg << endl;
#define DLOG_V(var) \
  cout << "#" << __LINE__ << ":" << #var << " : " << var << endl;
#else
#include <bits/stdc++.h>
#define DLOG(msg)
#define DLOG_V(var)
#endif
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<vector<pair<int, int>>> edges(n, vector<pair<int, int>>());
  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;
      edges[i].push_back(make_pair(v, c));
    }
  }
  int count = 1;
  constexpr auto not_yet = numeric_limits<int>::max();
  vector<int> costs(n, not_yet);
  costs[0] = 0;
  auto cmp = [](const pair<int, int>& lhs, const pair<int, int>& rhs) {
    return lhs.second > rhs.second;
  };
  priority_queue<pair<int, int>, vector<pair<int, int>>, decltype(cmp)> q(cmp);
  for (auto&& edge : edges[0]) {
    q.push(edge);
  }
  while (true) {
    auto state = q.top();
    q.pop();
    if (costs[state.first] > state.second) {
      assert(costs[state.first] == not_yet);
      for (auto&& edge : edges[state.first]) {
        q.push(make_pair(edge.first, edge.second + state.second));
      }
      costs[state.first] = state.second;
      if (++count == n) {
        break;
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    cout << i << " " << costs[i] << endl;
  }
}