Go: package main

import (
	"strconv"
	"fmt"
	"bufio"
	"os"
)
const INF = 1 << 21
var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}


func main() {
	scanner.Split(bufio.ScanWords)
	n := nextInt()
	adj := make([][]int, n)
	for i := range adj {
		adj[i] = make([]int, n)
	}

	for i := 0;i < n; i++ {
		u := nextInt()
		k := nextInt()
		for j := 0; j < k; j++ {
			v := nextInt()
			c := nextInt()
			adj[u][v] = c
		}
	}

	// for i := range adj {
	// 	fmt.Println(adj[i])
	// }

	dist := make([]int, n)
	prev := make([]int, n)
	visited := make([]bool, n)
	dijkstra := func(start int, size int) {
		for i := 0; i < size; i++ {
			dist[i] = INF
			prev[i] = -1
			visited[i] = false
		}
		dist[start] = 0
		for {
			u := -1
			tmp_min := INF
			for i := 0; i < size; i++ {
				if visited[i] == false && dist[i] < tmp_min {
					tmp_min = dist[i]
					u = i
				}
			}
			if u == -1 {
				break
			}
			visited[u] = true
			for i := 0; i < size; i++ {
				if adj[u][i] > 0 {
					w := adj[u][i]
					newlen := dist[u] + w
					if newlen < dist[i] {
						dist[i] = newlen
						prev[i] = u
					}
				}
			}
		}
	}
	dijkstra(0, n)
	for i, cost := range dist {
		fmt.Printf("%d %d\n", i, cost)
	}
}

C++: #include <iostream>
#include <vector>
#define INF 1e9
using namespace std;

int main(){
    //declaration and input
    int n;
    cin >> n;
    int u, k;
    vector<vector<int>> graph(n, vector<int>(n, INF));
    for (int i = 0; i < n; i++){
        cin >> u >> k;
        int v, c;
        for (int j = 0; j < k; j++){
            cin >> v >> c;
            graph[u][v] = c;
        }
    }
    vector<int> cost(n, INF);
    vector<int> parent_of(n, -1);
    vector<bool> is_visit(n, false);

    //Dijkstra
    //init
    cost[0] = 0;
    
    //loop
    while(true){
        int mincost = INF;
        int next = -1;
        for (int i = 0; i < n; i++){
            if (!is_visit[i] && cost[i] < mincost){
                mincost = cost[i];
                next = i;
            }
        }
        if (next == -1)
            break;
        is_visit[next] = true;
        for (int i = 0; i < n; i++){
            if (!is_visit[i] && graph[next][i] < INF){
                if (cost[next] + graph[next][i] < cost[i]){
                    cost[i] = cost[next] + graph[next][i];
                    parent_of[i] = next;
                }
            }
        }
    }

    //output
    for (int i = 0; i < n; i++)
        cout << i << ' ' << cost[i] << endl;
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define INF 1<<20

using namespace std;

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

int cost[105][105];
int d[105];
bool used[105];

int dijkstra (int n )
{
	memset (used, false, sizeof (used ) );
	fill (d, d+n, INF );
	d[0] = 0;

	while (true ){
		int v = -1;
		// まだ使われていない頂点のうち距離が最小のものを探す
		rep (u, n )
			if (!used[u] && (v == -1 || d[u] < d[v] ) ) v = u;
		
		if (v == -1 ) break;
		
		used[v] = true;
		rep (u, n )
			d[u] = min (d[u], d[v] + cost[v][u] );
	} // end whle
}

int main()
{
	ios_base::sync_with_stdio(0);
	int n; cin >> n;
	rep (i, n ) rep (j, n ) cost[i][j] = INF;

	rep (i, n ){
		int u; cin >> u;
		int k; cin >> k;
		while (k-- ){
			int v, c; cin >> v >> c;
			cost[u][v] = c;
		} // end while
	} // end loop

	dijkstra (n );
	rep (i, n ) cout << i << ' ' << d[i] << endl;
		
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <queue>


void update(int node, std::vector<int>& weight, const std::vector<std::map<int, int>> link_list) {
    for (auto && l : link_list[node]) {
        if (weight[l.first] == -1 || weight[node] + l.second < weight[l.first]) {
            weight[l.first] = weight[node] + l.second;
            update(l.first, weight, link_list);
        }
    }
}


int main() {
    int n;
    std::cin >> n;

    std::vector<std::map<int, int>> link_list;
    for (int i = 0; i < n; i++) {
        int u, k;
        std::cin >> u >> k;
        std::map<int, int> map;
        for (int j = 0; j < k; j++) {
            int c, v;
            std::cin >> c >> v;
            map[c] = v;
        }
        link_list.emplace_back(map);
    }

    std::vector<int> weight(n, -1);
    weight[0] = 0;

    auto comp = [] (std::tuple<int, int, int> &lfs, std::tuple<int, int, int> &rhs) {
        return std::get<2>(lfs) > std::get<2>(rhs);
    };
    
    std::priority_queue<std::tuple<int, int, int>, std::vector<std::tuple<int, int, int>>, decltype(comp)> que(comp);
    for (auto && m : link_list[0]) {
        que.push(std::make_tuple(0, m.first, m.second));
    }

    while (!que.empty()) {
        auto val = que.top();
        que.pop();
        auto w = weight[std::get<0>(val)] + std::get<2>(val);
        if (weight[std::get<1>(val)] == -1 || w < weight[std::get<1>(val)]) {
            weight[std::get<1>(val)] = w;
            for (auto && m : link_list[std::get<1>(val)]) {
                que.push(std::make_tuple(std::get<1>(val), m.first, m.second));
            }
        }
    }

    for (int i = 0; i < n; i++) {
        std::cout << i << " " << weight[i] << std::endl;
    }
}