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

struct Edge {
  int from, to, weight;
  Edge(int from, int to, int weight) : from(from), to(to), weight(weight) {}
};

struct Node {
  std::vector<Edge> ongoingEdges;
  void addEdge(Edge edge) {
    ongoingEdges.push_back(edge);
  }
};

class Graph {
private:
  std::vector<Node> nodes;
  int size;
public:
  Graph(int size): size(size) {
    nodes.resize(size);
  }
  void addEdge(Edge edge) {
    nodes[edge.from].addEdge(edge);
  }

  std::vector<int> calculateDist(int source) {
    std::vector<int> dist(size, (1 << 30));
    std::priority_queue< std::pair<int, int>, std::vector< std::pair<int, int> >, std::greater< std::pair<int, int> > > pq;

    pq.push(std::make_pair(0, source));
    dist[source] = 0;

    while(!pq.empty()) {
      int from = pq.top().second;
      pq.pop();

      for(Edge edge: nodes[from].ongoingEdges) {
        if(dist[edge.to] > dist[from] + edge.weight) {
          dist[edge.to] = dist[from] + edge.weight;
          pq.push({dist[edge.to], edge.to});
        }
      }

    }

    return dist;
  }
};

int main() {
  int n;
  std::cin >> n;
  Graph graph(n);

  for(int i = 0; i < n; i++) {
    int u, k;
    std::cin >> u >> k;

    for(int i = 0; i < k; i++) {
      int v, c;
      std::cin >> v >> c;
      graph.addEdge(Edge(u, v, c));
    }

  }

  std::vector<int> dist = graph.calculateDist(0);

  for(int i = 0; i < n; i++) {
    std::cout << i << ' ' << dist[i] << std::endl;
  }

}

C++: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (ll)(1E9+7)
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}

#define MAX_V 100

struct edge {
	edge(int a, int b) {
		cost = a;
		to = b;
	}
	int cost;
	int to;
};

int n;
vector<vector<edge>> G;
vector<int> d;

void dijkstra(int s) {
	priority_queue<pii, vector<pii>, greater<pii>> que;
	d[s] = 0;
	que.push(pii(0, s));

	while (!que.empty()) {
		pii p = que.top();
		que.pop();
		int v = p.second;
		if (d[v] < p.first) continue;
		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(pii(d[e.to], e.to));
			}
		}
	}

}

int main() {
	int n,u,k,tmpp,tmpw;
	cin >> n;
	d = vector<int>(n, INF);
	G = vector<vector<edge>>(n);
	rep (i,n) {
		cin >> u >> k;
		rep(j, k) {
			cin >> tmpp>>tmpw;
			G[u].emplace_back(tmpw, tmpp);
		}
	}
	dijkstra(0);
	rep(i, n) {
		cout << i << " " << d[i] << endl;
	}
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <vector>
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstring>
#include <queue>
#include <string>


using namespace std;

const double PI = 3.14159265358979;

int G[101][101];
int visited[101];
int n;

int d[101];
int p[101];

void dijkstra(int startpoint) {

	for (int i = 0; i < n; i++)	{
		d[i] = INT_MAX;
		p[i] = -1;
	}

	d[startpoint] = 0;

	while (true) {

		int minx = INT_MAX;
		int u = -1;
		for (int i = 0; i < n; i++)	{
			if (!visited[i] && minx > d[i]) {
				minx = d[i];
				u = i;
			}
		}
		if (u == -1) break;

		visited[u] = 1;
		
		for (int i = 0; i < n; i++)	{
			if (!visited[i] && G[u][i] < INT_MAX) {
				if (d[u] + G[u][i] < d[i]) {
					d[i] = d[u] + G[u][i];
					p[i] = u;
				}
			}
		}
	}
}

int main() {
	
	
	cin >> n;
	for (int i = 0; i < n; i++)	{
		for (int j = 0; j < n; j++) {
			G[i][j] = INT_MAX;
		}
	}

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

	dijkstra(0);

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

	return 0;
}