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;

//def
#define debug(x) cout << #x << ": " << x << '\n'
#define out(x) cout << x << '\n'
#define repeat(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define revrepeat(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr int MOD = 1e9 + 7;
constexpr int INF = __INT_MAX__;               // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

int pre[MAX_N];
long long d[MAX_N];
bool seen[MAX_N];
struct Edge {
    int to;
    long long cost;
};
// require: cost value is positive
// O(nlog|v|)
void dijkstra(int s, vector<vector<Edge>> &graph) {
    fill(pre, pre + MAX_N, -1);
    fill(seen, seen + MAX_N, false);
    fill(d, d + MAX_N, INF);

    auto comPair = [](const P one, const P two) {
        return one.second > two.second;
    };
    // que(v, distance)
    priority_queue<P, vector<P>, decltype(comPair)> que(comPair);
    que.emplace(0, 0);
    d[0] = 0;
    seen[0] = true;

    while (!que.empty()) {
        int u = que.top().first;
        que.pop();

        for (auto e : graph[u]) {
            int v = e.to;
            int c = e.cost;

            if (not seen[v] and d[v] > d[u] + c) {
                d[v] = d[u] + c;
                pre[v] = u;
                que.emplace(v, d[v]);
            }
        }
        seen[u] = true;
    }
};

int main() {
    int n;
    cin >> n;
    vector<vector<Edge>> graph(n);
    int k;
    rep(i, n) {
        cin >> k;
        cin >> k;
        rep(j, k) {
            Edge e;
            cin >> e.to >> e.cost;
            graph[i].push_back(e);
        }
    }
    dijkstra(0, graph);
    rep(i, n) {
        cout << i << ' ' << d[i] << endl;
    }
}

C++: 
#include<iostream>
#include<cstdio>
#include<set>
#include<queue>
#include<cstring>
#include<algorithm>
typedef long long ll;
#define inf 1000000000
using namespace std;


struct _node
{
	ll v,w;
	//:v(a),w(b)
	_node(ll a=0,ll b=0)
	{
		v=a;
		w=b;
	
	};
	bool operator <(const _node & other) const
	{
		return other.w<w;
	}
	
}node;

vector<_node> A[10500];
bool mark[10500];
ll dis[10500];

priority_queue<_node> Q;

void add(ll a,ll b,ll c)
{
	//cout<<a<<" "<<b<<" "<<c<<endl; 
	A[a].push_back(_node(b,c));
	//cout<<A[a][0].w<<endl;
	
}


void dlsj(ll n)
{
	//while(!Q.empty())Q.pop();
	ll v,v1;
	_node tmp;
	for(int i=0;i<n;i++)dis[i]=inf;

	dis[0]=0;
	Q.push(_node(0,0));
	
	while(!Q.empty())
	{
		tmp=Q.top();
		Q.pop();
		v=tmp.v;
		//cout<<v<<endl;
		//cout<<A[v].size()<<endl;
		if(mark[v])continue;
		mark[v]=1;
		for(int i=0;i<A[v].size();i++)
		{
			
			if(mark[A[v][i].v])continue;
			v1=A[v][i].v;
			//cout<<i<<" "; 
			//cout<<dis[2]<<" "<<dis[A[v][i].v]<<" "<<dis[v]+A[v][i].w<<endl;
			//cout<<A[v][i].v<<endl;
			if(dis[v1]>dis[v]+A[v][i].w)
			{
				
				dis[v1]=dis[v]+A[v][i].w;
				
				Q.push(_node(A[v][i].v,dis[v1]));
				
			}
			
			
			
			
		} 
		
		
	}
	
	
	
	
}




int main()
{
	ll n;
	scanf("%lld",&n);
	add(0,0,0);
	for(int i=1;i<=n;i++)
	{
		ll u,k,a,b;
		scanf("%lld%lld",&u,&k);
		while(k--)
		{
			scanf("%lld%lld",&a,&b);
			add(u,a,b);
		}
		
		
		
		
	} 
	dlsj(n);
	for(int i=0;i<n;i++)
	{
		//cout<<"e"<<endl;
		cout<<i<<" "<<dis[i]<<endl;
		
	}
	
}

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

using namespace std;
 
vector<int> dijkstra(int s, vector<vector<pair<int, int> > >& G) {
	const int INF = 1e9;
	const int N = G.size();
	vector<int> cost(N, INF);
	priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > pq;
	cost[s] = 0;
	pq.push(make_pair(0, s));
	while (!pq.empty()) {
		pair<int, int> p = pq.top(); pq.pop();
		int now = p.second;
		if (cost[now] < p.first) continue;
		for (auto next : G[now]) {
			int nv = next.first, nw = next.second;
			if (cost[nv] > cost[now] + nw) {
				cost[nv] = cost[now] + nw;
				pq.push(make_pair(cost[nv], nv));
			}
		}
	}
	return cost;
}

int main() {
	int n; cin >> n;
	vector<vector<pair<int, int> > > G(n);
	for (int i = 0; i < n; ++i) {
		int u, k; cin >> u >> k;
		while (k--) {
			int v, c; cin >> v >> c;
			G[u].push_back(make_pair(v, c));
		}
	}
	vector<int> ans(dijkstra(0, G));
	for (int i = 0; i < n; ++i)
		cout << i << " " << ans[i] << endl;

	return 0;
}