Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

const T = 10000000

var n int
var A [101][101]int

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func Shortestsearch() {
	var Minimum int
	var d, color [100]int
	var u int

	for i := 0; i < n; i++ {
		d[i] = T
		color[i] = 0
	}

	d[0] = 0
	color[0] = 1

	for {
		Minimum = T
		u = -1
		for i := 0; i < n; i++ {
			if Minimum > d[i] && color[i] != 2 {
				u = i
				Minimum = d[i]
			}
		}
		if u == -1 {
			break
		}
		color[u] = 2
		for j := 0; j < n; j++ {
			if color[j] != 2 && A[u][j] != T {
				if d[j] > d[u]+A[u][j] {
					d[j] = d[u] + A[u][j]
					color[j] = 1
				}
			}
		}
	}
	for i := 0; i < n; i++ {
		fmt.Printf("%d %d\n", i, d[i])
	}
}
func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()

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

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <utility>
#include <limits.h>

#define DIRECTED true //有向か無向か
#define ull unsigned long long
#define mp(X , Y) make_pair(X , Y)

using namespace std;

bool operator>(const pair<ull,int> a, const pair<ull,int> b){
    return a.first > b.first;
}

class dijkstra{
public:
    int num;
    vector<ull> dist;
    vector<int> prev;

    vector<vector<pair<int,ull>>> side; 

    dijkstra(){
    }

    dijkstra(int n){

        num = n;
        //0オリジンとの混合を避けるため+1する
        for(int i = 0; i < n + 1; i++){
            dist.push_back(ULONG_LONG_MAX);
            prev.push_back(-1);
            vector<pair<int,ull>> v;
            side.push_back(v);
        }
    }

    void reset(){
        dist.clear();
        prev.clear();

        for(int i = 0; i < num + 1; i++){
            dist.push_back(ULONG_LONG_MAX);
            prev.push_back(-1);

        }
    }

    void input(int f, int t,ull d){

        side[f].push_back(mp(t, d));
        if(!DIRECTED) side[t].push_back(mp(f,d));
    }

    void search(int start){
        
        dist[start] = 0;
        prev[start] = 0;

        priority_queue<pair<ull,int>, vector<pair<ull,int>>, greater<pair<ull,int>>> pq;
        pq.push(mp(0,start));

        while(!pq.empty()){
            
            ull d = pq.top().first;
            int s = pq.top().second;

            for(auto itr = side[s].begin(); itr != side[s].end(); itr++){

                ull tmp_d = (*itr).second;
                int to = (*itr).first; 

                if(dist[to] > d + tmp_d){
                    dist[to] = d + tmp_d;
                    prev[to] = s;
                    pq.push(mp(d + tmp_d,to));
                }
            }

            pq.pop();
        }
    }

    ull min_distance(int to){
        return dist[to];
    }

};

int main(){

    int n,u,k;

    cin >> n;

    dijkstra dijk;
    dijk = dijkstra(n);

    for(int i = 0; i < n; i++){
        scanf(" %d %d",&u,&k);
        for(int j = 0; j < k; j++){
            int v;
            ull c;

            scanf(" %d %llu",&v,&c);

            dijk.input(u,v,c);

        }
    }

    dijk.search(0);
    for(int i = 0; i < n; i++){
        cout << i << " " << dijk.min_distance(i) << endl;
    }
}