Go: package main

import (
	"bufio"
	"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
type Node struct {
	cost int
	done bool
}

type Edge struct {
	to, cost int
}

const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	nodes := make([]Node, N)
	for i := 0; i < N; i++ {
		nodes[i].cost = INF
	}
	E := make([][]Edge, N)
	for i := 0; i < N; i++ {
		id, k := sc.nextInt(), sc.nextInt()
		for j := 0; j < k; j++ {
			to, cost := sc.nextInt(), sc.nextInt()
			E[id] = append(E[id], Edge{to, cost})
		}
	}
	nodes[0].cost = 0
	for {
		cur := 0
		minCost := INF
		for i := 0; i < N; i++ {
			n := nodes[i]
			if !n.done && n.cost < minCost {
				cur = i
				minCost = n.cost
			}
		}
		if minCost == INF {
			break
		}
		nodes[cur].done = true
		for i := 0; i < len(E[cur]); i++ {
			to, cost := E[cur][i].to, E[cur][i].cost+nodes[cur].cost
			if !nodes[to].done && cost < nodes[to].cost {
				nodes[to].cost = cost
			}
		}
	}

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

C++: #include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
typedef map<int, vector<int>> Graph;
typedef map<int, map<int, int>> WGraph;
typedef pair<int, int> Edge;

map<Edge, bool> mp;
map<int, int> back;
vector<int> dijkstra(int v, WGraph &g, int r)
{
    vector<int> cost(v, 1 << 30);
    cost[r] = 0;
    priority_queue<pair<int, int>> pq;

    pq.push({0, r});

    while (!pq.empty())
    {
        //cerr << "-------------------------------" << endl;
        auto t = pq.top();
        pq.pop();
        //cerr << t.second << "," << t.first << endl;
        if (cost[t.second] < -t.first)
        {
            continue;
        }
        for (auto x : g[t.second])
        {
            if (cost[x.first] > cost[t.second] + g[t.second][x.first])
            {
                cost[x.first] = cost[t.second] + g[t.second][x.first];
                //cerr << "update cost[" << x.first << "] with " << cost[x.first] << endl;
                back[x.first] = t.second;
                pq.push({-cost[x.first], x.first});
            }
        }
    }
    return cost;
}

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    WGraph g;
    rep(i, n)
    {
        int k;
        cin >> k >> k;
        rep(j, k)
        {
            int v, c;
            cin >> v >> c;
            g[i][v] = c;
        }
    }
    auto cost = dijkstra(n, g, 0);
    rep(i, n)
    {
        cout << i << " " << cost[i] << endl;
    }
    return 0;
}

C++: #include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <sstream>
#include <fstream>
#include <iostream>
#include <algorithm>
using namespace std;

struct node {
	short id;
	long cost;
	node(short i, long c){
		this->id = i;
		this->cost = c;
	}
	bool operator<(node c) const {
		return this->cost > c.cost;
	}
};

int main() {
	int n;
	scanf("%d", &n);
	
	int c[n];
	int w[n][n];
	for(int i = 0; i < n; i++){
		int u, k;
		scanf("%d %d", &u, &k);
		
		c[u] = u ? LONG_MAX : 0;
		for(int j = 0; j < n; j++){
			w[u][j] = -1;
		}
		while(k--){
			int v, c;
			scanf("%d %d", &v, &c);
			w[u][v] = w[v][u] = c;
		}
	}
	
	priority_queue<node> q;
	q.push(*new node(0, 0));
	while(q.size()){
		int i = q.top().id;
		int ca = q.top().cost;
		q.pop();
		
		for(int j = 0; j < n; j++){
			if(w[i][j] != -1 && c[j] > w[i][j] + ca){
				c[j] = w[i][j] + ca;
				q.push(*new node(j, c[j]));
			}
		}
	}
	
	for(int i = 0; i < n; i++){
		printf("%d %d\n", i, c[i]);
	}
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;

const int MAX_N = 105;
int g[MAX_N][MAX_N];
int d[MAX_N];
bool used[MAX_N];
int n;

void dijkstra(int s){
    fill(d,d+n,inf);
    fill(used,used+n,false);
    d[s] = 0;

    while(true){
        int v = -1;
        for(int u = 0; u < n; u++){
            if(!used[u] && (v == -1 || d[u] < d[v])){
                // 1番最小のd[u]となるuを、v = u　として保存
                // ループを抜けた後に、vを介して[u]を更新
                v = u;
            }
        }
        //　この時点でd[u]が最小となるuは決定されている。
        if(v == -1) break;
        used[v] = true;
        for(int u = 0; u < n; u++){
            d[u] = min(d[u],d[v] + g[v][u]);
        }
    }
}

int main()
{
    cin >> n;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            g[i][j] = inf;
        }
    }
    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;
            g[u][v] = c;
        }
    }
    dijkstra(0);
    for(int i = 0; i < n; i++){
        cout << i << ' ' << d[i] << endl;
    }
}