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 MOD 1000000007
#define INF 1<<30
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define RREP(i,a,b) for(ll i=(a); i>=(b); i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pl;
typedef vector<pair<ll, ll>> vpl;

vpl adj[10005];
ll n;

void dijkstra(){
    priority_queue<pl> pq;
    vl d(105,INF);
    int visit[105] = {};
    d[0] = 0;
    pq.push(make_pair(0,0));
    while(!pq.empty()){
        pl p = pq.top(); pq.pop();
        ll u = p.second;
        visit[u] = 1;
        if(d[u] < p.first * (-1)) continue;
        rep(i,adj[u].size()){
            ll v = adj[u][i].first;
            if(visit[v] == 1) continue;
            if(d[v] > d[u] + adj[u][i].second){
                d[v] = d[u] + adj[u][i].second;
                pq.push(make_pair(d[v]*(-1),v));
            }
        }
    }
    rep(i,n){
        cout << i << " " << ((d[i] == INF) ? -1 : d[i]) << "\n";
    }
}

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

    dijkstra();

    return 0;
}

C++: // ALDS1_12_B: Single Shortest Path I
#include <iostream>
#include <vector>
#include <algorithm>
#define INF 1000000
#define NIL -1
using graph = std::vector<std::vector<int>>;
bool debug = false;

graph adjacency_matrix;
std::vector<bool> node_stat;
std::vector<int> next_node, minimum_cost;

void dijkstra(int vertex) {
    if (debug) std::cout << "dijkstra(" << vertex << ")\n";
    node_stat.at(vertex) = false;

    for (int i=0; i<adjacency_matrix.at(vertex).size(); i++) {
        int next_vertex = i, edge_weight = adjacency_matrix.at(vertex).at(next_vertex);
        if (edge_weight != -1) {
            int cost_to_next = minimum_cost.at(vertex) + edge_weight;
            if (cost_to_next < minimum_cost.at(next_vertex)) {
                if (debug) std::cout << vertex << " -> " << next_vertex << ": " << cost_to_next << "\n";
                minimum_cost.at(next_vertex) = cost_to_next;
                next_node.at(vertex) = next_vertex;
            }
        }
    }

    int min_weight = INF, next_vertex = NIL;
    for (int i=0; i<minimum_cost.size(); i++) {
        if (minimum_cost.at(i) < min_weight) {
            if (node_stat.at(i)) {
                if (debug) std::cout << "i = " << i << "\n";
                min_weight = minimum_cost.at(i);
                next_vertex = i;
            }   
        }
    }
    if (debug) std::cout << "min_weight = " << min_weight << ", next_vertex = " << next_vertex << "\n";
    if (next_vertex == NIL) {
        return;
    }
    dijkstra(next_vertex);
}

void init() {
    node_stat.assign(node_stat.size(), true);
    next_node.assign(next_node.size(), NIL);
    minimum_cost.assign(minimum_cost.size(), INF);
    minimum_cost.at(0) = 0;
}

int main() {
    int total_node_num; std::cin >> total_node_num;
    
    adjacency_matrix.resize(total_node_num);
    for (int i=0; i<adjacency_matrix.size(); i++) adjacency_matrix.at(i).assign(total_node_num, NIL);
    node_stat.resize(total_node_num);
    next_node.resize(total_node_num);
    minimum_cost.resize(total_node_num);
    
    for (int i=0; i<total_node_num; i++) {
        int vertex_num; std::cin >> vertex_num;
        int outdegree; std::cin >> outdegree;
        for (int j=0; j<outdegree; j++) {
            int next_vertex; std::cin >> next_vertex;
            std::cin >> adjacency_matrix.at(vertex_num).at(next_vertex);
        }
    }
    init();
    dijkstra(0);
    for (int i=0; i<minimum_cost.size(); i++) {
        std::cout << i << " " << minimum_cost.at(i) << "\n";
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

#define MAX 100
#define INFTY (1 << 21)
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[MAX][MAX], d[MAX], color[MAX];

void shortestPath(int s){
    int u, minv;
    //距離を初期化
    for(int i = 0; i < n; i++){
        d[i] = INFTY;
        color[i] = WHITE;
    }

    d[s] = 0;

    while(1){
        int u = -1;
        int minv = INFTY;
        //最も距離が近いものを更新
        for(int i = 0; i < n; i++){
            if(color[i] != BLACK && d[i] < INFTY){
                if(d[i] < minv){
                    u = i;
                    minv = d[i];
                }
            }
        }

        if(u == -1) break;
        color[u] = BLACK;

        for(int v = 0; v < n; v++){
            d[v] = min(d[v], d[u] + M[u][v]);
        }
    }
}

int main(){
    cin >> n;
    //隣接行列を作製

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

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

    shortestPath(0);

    rep(i,n){
        cout << i << " " << d[i] << endl;
    }

    return 0;
}