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;

typedef pair<int, int> P;

struct Edge {
  int to, cost;
};

int n;
vector<vector<Edge> > G;

vector<int> dij() {
  priority_queue<P, vector<P>, greater<P> > Q;
  vector<int> d(n, -1);
  Q.push({0, 0});
  while ( !Q.empty() ) {
    P p = Q.top(); Q.pop();
    int v = p.second, c = p.first;

    if ( d[v] >= 0 ) continue;
    d[v] = c;
    
    for ( Edge e: G[v] ) {
      Q.push({c+e.cost, e.to});
    }    
  }

  return d;
}

int main() {
  cin >> n;

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

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

C++: #include <iostream>
#include <vector>
#include <queue>
using namespace std;
static const int MAX = 10000;
static const int INFTY = (1<<21);

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

  cin >> 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;
      adj[u].emplace_back(v, c);
    }
  }

  priority_queue<pair<int,int>> PQ;
  int d[MAX];
  bool visited[MAX];
  for (int i = 0; i < n; ++i)
  {
    d[i] = INFTY;
    visited[i] = false;
  }
  d[0] = 0;
  PQ.emplace(0,0);

  while (!PQ.empty())
  {
    pair<int,int> f = PQ.top(); PQ.pop();
    int u = f.second;
    visited[u] = true;
    if (d[u] < f.first * (-1)) continue;

    for (int i = 0; i < adj[u].size(); ++i)
    {
      int v = adj[u][i].first;
      if (visited[v]) continue;
      if (d[v] > d[u] + adj[u][i].second)
      {
        d[v] = d[u] + adj[u][i].second;
        PQ.emplace(d[v] * (-1), v);
      }
    }
  }

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

  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
struct node{
	int v,c;
	bool operator<(const node&p)const{
		return c>p.c;
	}
};
int d[100005];
vector<node> e[100005];
bool ok[100005];
int n;
void solve(){
	priority_queue<node> q;
	ok[0]=1;
	for(int i=0;i<e[0].size();i++)q.push(e[0][i]);
	int k=1;
	while(k!=n){
		node v=q.top();q.pop();
		if(ok[v.v])continue;
		d[v.v]=v.c;
		ok[v.v]=1;
		k++;
		for(int j=0;j<e[v.v].size();j++)
			q.push({e[v.v][j].v,e[v.v][j].c+v.c});
	}
	for(int i=0;i<n;i++)
		cout<<i<<' '<<d[i]<<"\n";
}
int main(){
//	freopen("a.txt","r",stdin);
	cin.tie(0);
	int u,v,k,c;
	cin>>n;
	while(cin>>u>>k){
		for(int i=0;i<k;i++){
			cin>>v>>c;
			e[u].push_back({v,c});
		}
	}
	solve();
	return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<vector<pair<int, int> > > vvp;
typedef vector<pair<int,int> > vp;
typedef vector<vector<int> > vvi;
typedef vector<int> vi;
typedef vector<vector<bool> > vvb;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef pair<string, int> psi;
typedef pair<int, int> pii;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define yn(f) (f?"yes":"no")
#define YN(f) (f?"YES":"NO")
#define Yn(f) (f?"Yes":"No")
#define mod 1000000007
#define intmax 2147483647
#define intmin -2147483648
#define longmax 9223372036854775807
#define longmin -9223372036854775808
#define black 0
#define gray 127
#define white 255
int main() {
	int N;
	cin >> N;
	vvp A(N);
	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;
			A[u].push_back(make_pair(v,w));
		}
	}
	vi color(N,black);
	priority_queue<pii,vp,greater<pii> > pq;
	vi mincost(N,intmax);
	color[0] = gray;
	pq.push(make_pair(0,0));
	mincost[0] = 0;
	while (!pq.empty()) {
		pii minp = pq.top();
		pq.pop();
		color[minp.second] = white;
		if (mincost[minp.second]<minp.first) continue; 
		for (int i = 0; i < A[minp.second].size(); i++)
		{
			int u = A[minp.second][i].first;
			if (color[u]!=white&&mincost[u]>mincost[minp.second]+ A[minp.second][i].second) {
				mincost[u] = mincost[minp.second] + A[minp.second][i].second;
				pq.push(make_pair(mincost[u],u));
				color[u] = gray;
			}
		}
	}
	for (int i = 0; i < N; i++)
	{
		cout << i << " " << mincost[i] << endl;
	}
};