Go: package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

const (
	INFTY = 1 << 21
	NIL   = -1
)

const (
	WHITE = iota
	GRAY
	BLACK
)

type Graph [][]int

func (g *Graph) dikstra(n int) string {
	var (
		u, minv = 0, 0
	)

	d := make([]int, n)
	color := make([]int, n)

	for i := 0; i < n; i++ {
		d[i] = INFTY
		color[i] = WHITE
	}
	d[0] = 0
	color[0] = GRAY

	for {
		minv = INFTY
		u = -1
		for 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 v := 0; v < n; v++ {
			if color[v] != BLACK && (*g)[u][v] != INFTY {
				if d[v] > d[u]+(*g)[u][v] {
					d[v] = d[u] + (*g)[u][v]
					color[v] = GRAY
				}
			}
		}
	}

	var out bytes.Buffer
	for i := 0; i < n; i++ {
		out.WriteString(fmt.Sprintf("%d ", i))
		if d[i] == INFTY {
			out.WriteString(fmt.Sprintf("%d\n", -1))
			continue
		}
		out.WriteString(fmt.Sprintf("%d\n", d[i]))
	}

	return strings.TrimRight(out.String(), "\n")
}

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	g := make(Graph, n)
	for i := 0; i < n; i++ {
		g[i] = make([]int, n)
		for j := 0; j < n; j++ {
			g[i][j] = INFTY
		}
	}

	for i := 0; i < n; i++ {
		sc.Scan()
		u, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())

		for j := 0; j < k; j++ {
			sc.Scan()
			v, _ := strconv.Atoi(sc.Text())
			sc.Scan()
			c, _ := strconv.Atoi(sc.Text())

			g[u][v] = c
		}
	}

	return g.dikstra(n)
}

func main() {
	fmt.Println(answer(os.Stdin))
}

C++: #include<iostream>
#define INF 1<<21
using namespace std;
static const int N = 101;
int n,A[N][N];
void dikstra(void){
    int d[N],p[N],color[N],minv;
    for(int i=0;i<n;i++){
        d[i] = INF;
        p[i] = -1;
        color[i] = 0;
    }
    d[0] = 0;
    while(1){
        int u =-1;
        minv = INF;
        for(int i=0;i<n;i++){
            if(d[i]<minv && color[i]!=1){
                u = i;
                minv = d[i];
            }
        }
        if(u==-1){
            break;
        }
        color[u] = 1;
        for(int v=0;v<n;v++){
            if(d[u]+ A[u][v] < d[v]){
                d[v] = d[u] + A[u][v];
                p[v] = u;
            }
        }
    }
    for(int i=0;i<n;i++){
        cout << i << ' ' << d[i] << endl;
    }
}
int main(void){
    int u,adj,v;
    cin >> n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            A[i][j] = INF;
        }
    }
    for(int i=0;i<n;i++){
        cin >> u >> adj;
        for(int j=0;j<adj;j++){
            cin >> v >> A[u][v];
        }
    }
    dikstra();
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
static const int MAX = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
static const int INFTY = (1<<21);
int n,M[MAX][MAX];

void dijkstra(){
    int color[MAX],d[MAX],p[MAX];
    int minv;
    for (int i = 0; i < n; i++)
    {
        color[i] = WHITE;
        d[i] = INFTY;
        
    }
    d[0] = 0;color[0] = GRAY;
    while (1)
    {
        minv = INFTY;
        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){
                if(d[v]>d[u]+M[u][v]){
                    d[v] = d[u] + M[u][v];
                    color[v] = GRAY;
                }
            }
        }
    }
    for (int  i = 0; i < n; i++)
        {
            cout << i << " " << (d[i]==INFTY?-1:d[i]) << endl;
        }  
}


int main(){
    cin >> n;
    int u,k,c,v;
    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++){
        cin >> u >> k;
        for (int j = 0; j < k; j++){
            cin >> v>> c;
            M[u][v] = c;
        }
    }
    dijkstra();
    return 0;
    
}

C++: #include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1LL<<60;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

struct Edge{
    int u;
    int v;
    int cost;

    Edge(int _u, int _v, int c) {
        u = _u;
        v = _v;
        cost = c;
    }
};

vector<Edge> adj;
int dist[110];

int main() {
    int n; cin >> n;
    rep(i, n) {
        int u, k; cin >> u >> k;
        rep(j, k) {
            int v, c; cin >> v >> c;
            adj.emplace_back(Edge(u, v, c));
        }
    }

    // 初期化
    rep(i, n) {
        dist[i] = (i == 0) ? 0 : INT_INF;
    }

    for (int i = 1; i < n; i++) {
        for (auto edge: adj) {
            int u = edge.u;
            int v = edge.v;
            int c = edge.cost;
            // cout << '(' << u << ',' << v << ',' << c << ')' << endl;
            if (dist[u] != INT_INF && dist[v] > dist[u] + c) {
                dist[v] = dist[u] + c;
            }
        }
    }

    rep(i, n) {
        cout << i << ' ' << dist[i] << endl;
    }
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

const int MAX = 100;
const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;
int n, M[MAX][MAX];

int dijkstra()
{
	int minv;
	int d[MAX];
	int color[MAX];

	for (int i = 0; i < n; i++) {
		d[i] = INF;
		color[i] = WHITE;
	}

	d[0] = 0;
	color[0] = GRAY;

	while (1) {
		minv = 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 (M[u][v] != INF && color[v] != BLACK) {
				if (d[v] > d[u] + M[u][v]) {
					d[v] = d[u] + M[u][v];
					color[v] = GRAY;
				}
			}
		}
	}

	for (int i = 0; i < n; i++) {
		cout << i << (d[i] == INF ? -1 : d[i]) << endl;
	}

	return 0;
}

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

	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;
}