Go: package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const INF = 1 << 60

type Edge struct {
	to, cost int
}

type Node struct {
	id, cost int
}

type PQ []Node

func (pq PQ) Len() int           { return len(pq) }
func (pq PQ) Less(i, j int) bool { return pq[i].cost < pq[j].cost }
func (pq PQ) Swap(i, j int)      { pq[i], pq[j] = pq[j], pq[i] }

func (pq *PQ) Push(x interface{}) {
	*pq = append(*pq, x.(Node))
}

func (pq *PQ) Pop() interface{} {
	old := *pq
	n := len(old)
	x := old[n-1]
	*pq = old[0 : n-1]
	return x
}

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	E := make([][]Edge, N)
	for i := 0; i < N; i++ {
		id, k := sc.nextInt(), sc.nextInt()
		E[id] = make([]Edge, k)
		for j := 0; j < k; j++ {
			to, cost := sc.nextInt(), sc.nextInt()
			E[id][j] = Edge{to, cost}
		}
	}

	d := make([]int, N)
	for i := 0; i < N; i++ {
		d[i] = INF
	}
	done := make([]bool, N)
	pq := &PQ{}
	heap.Init(pq)
	d[0] = 0
	heap.Push(pq, Node{0, 0})
	for pq.Len() > 0 {
		cur := heap.Pop(pq).(Node).id
		if done[cur] {
			continue
		}
		done[cur] = true
		for i := 0; i < len(E[cur]); i++ {
			to, cost := E[cur][i].to, E[cur][i].cost+d[cur]
			if !done[to] && cost < d[to] {
				d[to] = cost
				heap.Push(pq, Node{to, cost})
			}
		}
	}

	for i := 0; i < N; i++ {
		fmt.Fprintln(wtr, i, d[i])
	}
	wtr.Flush()
}

C++: #include <bits/stdc++.h>

#define NIL -2
#define INF 1000000001

using namespace std;
static const int BLK = 2;
static const int GRY = 1;
static const int WHT = 0;

void dijkstra(const vector<vector<pair<int,int> > > &adj_list, 
                    vector<int> &color, 
                    vector<int> &parent, 
                    vector<int> &minpath,
                    int start_node)
{
    priority_queue<pair<int,int>,vector<pair<int,int> >, greater<pair<int,int> > >  PQ;
    PQ.push(make_pair(start_node,0));

    while(!PQ.empty()){
        pair<int,int> t = PQ.top(); PQ.pop();
        int u = t.second;
        color[u] = BLK;
        if(minpath[u] < t.first) continue;
        for(int i = 0;i < adj_list[u].size();i++){
            int v = adj_list[u][i].first;
            if(color[v] != BLK){
                if(minpath[u] + adj_list[u][i].second < minpath[v]){
                    minpath[v] = minpath[u] + adj_list[u][i].second;
                    parent[v] = u;
                    color[v] = GRY;
                    PQ.push(make_pair(minpath[v],v));
                }  
            }
        }
        
    }

}


int main(){
    int mat_size;
    int node, deg;
    int to,weight;
    int temp;
    int cost = 0;

    scanf("%d",&mat_size);
    vector<vector<pair<int,int> > > adj_list(mat_size);
    vector<int> color(mat_size,WHT);
    vector<int> minpath(mat_size,INF);
    vector<int> parent(mat_size,-1);
    
    for(int i = 0;i < mat_size;i++){
        scanf("%d %d",&node,&deg);
        for(int j = 0;j < deg;j++){
            scanf("%d %d", &to, &weight);
            adj_list[node].push_back(make_pair(to,weight));
        }
    }
    
    minpath[0] = 0;
    dijkstra(adj_list,color,parent,minpath,0);

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

    return 0;   
}

C++: #include<stdio.h>
#include<queue>
#include<string.h>
using namespace std;
#define INF 1 << 30
struct ss{
	int next;
	int to;
	int val;
}e[100050];
int head[100050];
int tot;
void add(int x,int y,int val){
	e[tot].next=head[x];
	e[tot].to=y;
	e[tot].val=val;
	head[x]=tot++;
}
int n;
int vis[100050]={0};
int dis[10005];
void spfa(){
	for(int i=0;i<n;i++){
		dis[i]=INF;
	}
	vis[0]=1;
	dis[0]=0;
	queue<int> st;
	st.push(0);
	while(!st.empty()){
		int t=st.front();
		st.pop();
		vis[t]=0;
		for(int i=head[t];i!=-1;i=e[i].next){
			int to=e[i].to;
			if(dis[to]>dis[t]+e[i].val){
				dis[to]=dis[t]+e[i].val;
				if(!vis[to]){
					st.push(to);
					vis[to]=1;
				}
			}
		}
	}
}
int main(){
	scanf("%d",&n);
	tot=0;
	memset(head,-1,sizeof(head));
	int a,to,val,num;
	for(int i=0;i<n;i++){
		scanf("%d %d",&a,&num);
		for(int j=1;j<=num;j++){
			scanf("%d %d",&to,&val);
			add(a,to,val);
		}
	}
	spfa();
	printf("0 0\n");
	for(int i=1;i<n;i++){
		printf("%d %d\n",i,dis[i]);
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define REPR(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
const int INF = 1001001001;
typedef pair<int,int> pii;

template<class t> inline bool chmax(t& a, t b) { if (a < b) { a = b; return 1; } return 0; }
template<class t> inline bool chmin(t& a, t b) { if (a > b) { a = b; return 1; } return 0; }

using Graph = vector<vector<pii> >;

int n;
vector<bool> seen;
vector<int> dist;
priority_queue<pair<int, int> > pq;

void dijkstra(const Graph &G, int v){
  seen[v] = true;

  for(pii p : G[v]){
    int u = p.first;
    int c = p.second;
    if(seen[u] == true) continue;
    if(chmin(dist[u], dist[v]+c)) pq.push(make_pair((-1)*dist[u], u));
  }

  while(!pq.empty()){
    pair<int, int> tmp;
    tmp = pq.top();
    pq.pop();
    if(seen[tmp.second]) continue;
    int nv = tmp.second;
    dijkstra(G, nv);
  }

  return;
}

int main(){
  cin >> n;

  Graph G(n);
  rep(i, n){
    int v, k; cin >> v >> k;
    rep(j, k){
      int u, c; cin >> u >> c;
      G[v].push_back(make_pair(u, c));
    }
  }

  seen.assign(n, false);
  dist.assign(n, INF);
  dist[0] = 0;
  dijkstra(G, 0);

  rep(i, n) cout << i << " " << dist[i] << endl;

  return 0;
}