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 <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <utility>
using namespace std;
//_____
#define pb push_back
#define fi first
#define se second
#define mkp make_pair
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define err(...) fprintf(stderr, __VA_ARGS__)
#define show(x) cerr << #x << ':' << x << endl
#define outl(x) cout << (x) << '\n'
#define FAST() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, B b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, B b){return b<a ? a=b,1 : 0;}
inline bool inside(int y, int x, int H, int W){return(y>=0 && x>=0 && y<H && x<W);}
const int dx[] = {1, 0, -1, 0,  1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1,  -1, 1, 1, -1};
#define INF 0x3f3f3f3f
#define LEN 1000011
#define NIL -1
//_______

int N;
vector <pii> G[101];
int mcos[101];

void dijkstra(int s)
{
   priority_queue < pii, vector<pii>, greater<pii> > pq;
   pq.push( mkp(0, s) );
   memset( mcos, INF, sizeof(mcos) );
   mcos[s] = 0;

   while( !pq.empty() ){
      const pii tmp = pq.top(); pq.pop();
      if( mcos[tmp.se] < tmp.fi )continue;

      for( const auto& v : G[tmp.se] ){
         const int nc = v.fi + tmp.fi;
         if( chmin( mcos[v.se], nc )) pq.push( mkp(nc, v.se) );
      }
   }
   return ;
}

signed main()
{
   FAST();
   cin >> N;
   rep(i, N){
      int u, k, to, c;
      cin >> u >> k;
      while(k--){
         cin >> to >> c;
         G[i].pb( mkp(c,to) );
      }
   }
   dijkstra(0);
   rep(i, N){
      cout << i << ' ' << mcos[i] << '\n';
   }
}

C++: #include<iostream>
#include<string>
using namespace std;

void dijkstra(int s);
const int Infty = 20000000;

int **M,*d,*p,n;
string *color;

int main(){
	cin>>n;
	M = new int*[n]; for(int i=0;i<n;i++) M[i] = new int[n];
	d = new int[n]; p = new int[n]; color = new string[n];
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++) M[i][j] = -1;
	}

	for(int i=0;i<n;i++){
		int vertex,deg,e,w;
		cin>>vertex>>deg;
		for(int j=0;j<deg;j++){
			cin>>e>>w;
			M[i][e]  = w;
		}
	}

	dijkstra(0);

	for(int i=0;i<n;i++) delete [] M[i]; delete [] M;
	delete [] d; delete [] p; delete [] color;
}

void dijkstra(int s){
	for(int i=0;i<n;i++){
		d[i] = Infty; color[i] = "WHITE";
	}
	d[s] = 0; p[s] = -1;

	while(true){
		int u , mindist = Infty;
		for(int i=0;i<n;i++){
			if(color[i]!="BLACK" && d[i]<mindist){
				mindist = d[i];
				u = i;
			}
		}

		if(mindist==Infty) break;

		color[u] = "BLACK";

		for(int v=0;v<n;v++){
			if(color[v]!="BLACK" && M[u][v]!=-1){
				if(d[u]+M[u][v]<d[v]){
					d[v] = d[u]+M[u][v];
					p[v] = u;
					color[v] = "GRAY";
				}
			}
		}
	}

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

C++: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n) ; i++)
constexpr auto INF = 2147483647;
typedef long long ll;

static const int MAX = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, Adj_Marix[MAX][MAX];

void dijkstra(){
  int minv;
  int distance[MAX], color[MAX];
  //init
  for(int i=0;i<n; i++){
    distance[i] = INF;
    color[i] = WHITE;
  }
  distance[0] = 0;
  color[0] = GRAY;
  while(1){
    minv = INF;
    int u  = -1;
    // Find next point
    for(int i =0; i<n; i++){
      if( minv > distance[i] && color[i] != BLACK){
        u = i;
        minv = distance[i];
      }
    }
    //if cant find next point
    if(u == -1) break;
    // Refresh dictance for adj points
    color[u] = BLACK;
    for(int v=0; v<n; v++){
      if(color[v] != BLACK && Adj_Marix[u][v] != INF){
        if(distance[v] > distance[u] + Adj_Marix[u][v]){
          distance[v] = distance[u] + Adj_Marix[u][v];
          color[v] = GRAY;
        }
      }
    }
  }
  for(int i =0; i<n; i++){
    cout << i << " " << (distance[i] == INF ? -1: distance[i] ) << endl;
  }
}

int main(){

  cin >> n;
  rep(i,n){
    rep(j,n){
      Adj_Marix[i][j] = INF;
    }
  }

  int k, c, u, v;
  rep(i,n){
    cin >> u >> k;
    rep(j,k){
      cin >> v >> c;
      Adj_Marix[u][v] = c;
    }
  }

  dijkstra();

  return 0;
}