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>
using namespace std;

const int MAX=10005;
int state[MAX],N,D[MAX];
vector<pair<int,int>> S[MAX];
priority_queue<pair<int,int>> Q;

void dijkstra(){
    int cnt=1;
    for(int i=0;i<N;i++){
        state[i]=0;
        D[i]=10000000;
    }
    state[0]=1;
    D[0]=0;
    for(int i=0;i<S[0].size();i++){
        Q.push(make_pair(-S[0][i].second,S[0][i].first));
        D[S[0][i].first]=min(D[S[0][i].first],D[0]+S[0][i].second);
    }
    while(1){
        int a=Q.top().second;
            if(state[a]==0){
            Q.pop();
            state[a]=1;
            for(int i=0;i<S[a].size();i++){
                if(state[S[a][i].first]==0){
                    Q.push(make_pair(-(D[a]+S[a][i].second),S[a][i].first));
                    D[S[a][i].first]=min(D[S[a][i].first],D[a]+S[a][i].second);
                }
            }
                cnt++;
        }
        else Q.pop();
        if(cnt==N) break;
    }
    return;
}


int main(){
    
    cin>>N;
    for(int i=0;i<N;i++){
        int l,a;cin>>l>>a;
        for(int j=0;j<a;j++){
            int b,c;cin>>b>>c;
            S[i].push_back(make_pair(b,c));
        }
    }
    dijkstra();
    for(int i=0;i<N;i++){
        cout<<i<<" "<<D[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;
}

C++: #include <iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

void dijkstra()
{
    int minv; // 最小のコスト
    int d[MAX], color[MAX]; // d[n]は始点からnまでの最短コスト，color[v]はvの訪問状態

    for (int i = 0; i < n; i++) {
        // 最短コストと訪問状態の初期化
        d[i] = INFTY;
        color[i] = WHITE;
    }

    d[0] = 0; // 始点から始点までの最短コストは0
    color[0] = GRAY; // 始点を訪問済みにする
    while (1) {
        minv = INFTY; // 最小コストをINFで初期化
        int u = -1; // 現在の頂点を初期化
        for (int i = 0; i < n; i++) {
            if (minv > d[i] && color[i] != BLACK) { // 訪問するコストが最小コストより小さく，未訪問のとき
                u = i; // 現在の頂点を変える
                minv = d[i]; // 最小コストを変える
            }
        }
        if (u == -1) {
            break;
        }
        color[u] = BLACK; // 最小コストの頂点へ進み，訪問済みとする
        for (int v = 0; v < n; v++) {
            if (color[v] != BLACK && M[u][v] != INFTY) { // vに訪問済みでなくu->vへのコストがINFでないとき
                if (d[v] > d[u] + M[u][v]) { // 「vへの最小コスト」より「現在までのコストと現在地からvまでのコストを加えたもの」のほうが小さい時
                    d[v] = d[u] + M[u][v]; // vまでのコストを更新
                    color[v] = GRAY; // vへ訪問済みとする
                }
            }
        }
    }
    for (int i = 0; i < n; i++) {
        cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
    }
}

int main()
{
    cin >> n;
    //
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            M[i][j] = INFTY;
        }
    }

    int k, c, u, v;
    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            cin >> v >> c;
            M[u][v] = c;
        }
    }

    dijkstra();

    return 0;
}

C++: #include <iostream>
#include <utility>
#include <vector>
#include <queue>
using namespace std;
#define INF 2000000000
int Min(int x,int y){
        return x>y?y:x;
}
int main(){
        int N;
        cin >> N;
        vector <vector <int> > adjancent(N,vector <int>(N,INF));
        for(int i=0 ; i<N ; i++ ){
                int n,degree,to,cost;
                cin >> n >> degree;
                for(int l=0 ; l<degree ; l++ ){
                        cin >> to >> cost;
                        adjancent[n][to]=cost;
                }
        }
        vector<int> dp(N,INF);
        dp[0]=0;
        bool sign=true;
        while(sign){
                sign=false;
                for(int now=0 ; now<N ; now++){
                        for(int i=0 ; i<N ; i++ ){
                                int tmp=dp[i];
                                dp[i]=Min(dp[i],dp[now]+adjancent[now][i]);
                                if(tmp!=dp[i])
                                        sign=true;
                        }
                }
        }
        for(int i=0 ; i<N ; i++ )
                cout <<i<<" "<<dp[i]<<endl;
        return 0;
}