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 <cstdio>
#include <algorithm>
#include <queue>
using namespace std;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;
vector<pair<int, int>> adj[100];
int *d;

void dijkstra() {
    priority_queue<pair<int, int>> PQ;
    int d[n], color[n];

    for (int i = 0; i < n; i++) {
        d[i] = INFTY;
        color[n] = WHITE;
    }
    d[0] = 0;
    PQ.push(make_pair(0, 0));

    while (!PQ.empty()) {
        pair<int, int> f = PQ.top();
        PQ.pop();

        int u = f.second;
        color[u] = BLACK;

        if (d[u] < f.first * (-1)) { continue; }

        for (int j = 0; j < adj[u].size(); j++) {
            int v = adj[u][j].first;
            if (color[v] == BLACK) { continue; }
            if (d[u] + adj[u][j].second < d[v]) {
                d[v] = d[u] + adj[u][j].second;
                // printf("d[%d] = %d\n", v, d[v]);
                PQ.push(make_pair(d[v] * (-1), v));
                color[v] = GRAY;
            }
        }
    }
    
    for (int i = 0; i < n; i++) {
        printf("%d %d\n", i, d[i]);
    }
}

int main() {
    scanf("%d", &n);

    // adj = new vector<pair<int, int>>[n];

    for (int i = 0; i < n; i++) {
        int u, k;
        scanf("%d %d", &u, &k);
        for (int j = 0; j < k; j++) {
            int v, c;
            scanf("%d %d", &v, &c);
            adj[u].push_back(make_pair(v, c));
        }
    }

    dijkstra();

    return 0;
}

C++: //さっさと済ませられるところはさっさと済ましてしまう．ただし注意深く
#include <cstdio>
#include <iostream>
#define MAX_VERTEXES 100
#define NIL -1
#define INFTY 20000000// >100*100000

using namespace std;

//think easy make easy

int n;//num of vertexes(頂点)
int matrix_graph[MAX_VERTEXES+1][MAX_VERTEXES+1];//0オリジン
bool vertex_set[MAX_VERTEXES+1];///0オリジン
int current_mincost[MAX_VERTEXES+1];//現時点での各頂点への最小コスト
bool candidate[MAX_VERTEXES+1];//次にvertex_setに加える頂点の候補
int new_vertex;

void findNextVertex(){
	int min_tmp=INFTY;
	int next_tmp = NIL;
	
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(i == new_vertex && vertex_set[j] == false){//わかりやすいプログラムほど処理もすくない.
				//無駄のないプログラムの方がわかりよい
				if(matrix_graph[i][j]+current_mincost[i] < current_mincost[j]
				   && matrix_graph[i][j] != NIL){
					   current_mincost[j]  = matrix_graph[i][j]+current_mincost[i];
					   candidate[j] = true;
				}
			}
		}
	}
	for(int i=0;i<n;i++){
		if(candidate[i] == true && current_mincost[i] < min_tmp){
			min_tmp = current_mincost[i];
			next_tmp = i;
		}
	}
	vertex_set[next_tmp] = true;
	candidate[next_tmp] = false;
	new_vertex = next_tmp;
}

int main(){
	scanf("%d",&n);

	int v_num;
	int k;//v_numの出次数

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

	for(int i=0;i<n;i++){
		scanf("%d",&v_num);
		scanf("%d",&k);

		for(int j=0;j<k;j++){
			int v_num2;
			int cst;
			scanf("%d",&v_num2);
			scanf("%d",&cst);
			matrix_graph[v_num][v_num2] = cst;
		}
	}

	for(int i=0;i<n;i++){
		vertex_set[i] = false;
		current_mincost[i] = INFTY;
	}
	/*確認用
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(j<n-1) printf("%d ",matrix_graph[i][j]);
			else printf("%d\n",matrix_graph[i][j]);
		}
	}
	*/

	for(int i=0;i<n;i++){
		candidate[i] = false;
	}

	vertex_set[0] = true;
	current_mincost[0] = 0;
	new_vertex = 0;

	for(int i=1;i<n;i++){
		//for(int j=0;j<n;j++){
			//cout <<" " <<vertex_set[j] ;
		//}
		cout <<endl;
		findNextVertex();
	}


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


	return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
const int MAX = 100;
const int INF = 200000;
int n, G[MAX][MAX];
int dis[MAX];
bool book[MAX] = { false };
void init()
{
	for (int i = 0; i < n; i++)
		dis[i] = G[0][i];
	book[0] = true;
}
void dijkstra()
{
	for (int k = 1; k <= n - 1; k++)
	{
		int min = INF;
		int u;
		for (int j = 0; j < n; j++)
			if (dis[j] > 0 && dis[j] < INF && !book[j] && dis[j] < min)
			{
				min = dis[j];
				u = j;
			}
		book[u] = true;
		for (int v = 0; v < n; v++)
			if (!book[v] && dis[u]+G[u][v] < dis[v])
				dis[v] = dis[u] + G[u][v];
	}
}
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			if (i != j)
				G[i][j] = INF;
			else
				G[i][j] = 0;
	for (int i = 0; i < n; i++)
	{
		int u, d;
		cin >> u >> d;
		for (int j = 0; j < d; j++)
		{
			int v, w;
			cin >> v >> w;
			G[u][v] = w;
		}
	}
	init();
	dijkstra();
	for (int i = 0; i < n; i++)
		cout << i << " " << dis[i] << endl;
}

C++: #include <bits/stdc++.h>

int INF = 900000000;
using pii = std::pair<int, int>;
std::vector<std::vector<pii>> g;
std::vector<bool> visited; 
std::vector<int> c; 
std::priority_queue<pii, std::vector<pii>, std::greater<pii>> q;

int n, p, x, y;
int discard;


int main() {
    std::cin >> n;
    visited.assign(n, false);
    g.assign(n, std::vector<pii>(0));
    c.assign(n, INF);
    for (int i = 0; i < n; i++) {
        std::cin >> discard >> p;
        for (int k = 0; k < p; k++) {
            std::cin >> x >> y;
            g[i].push_back(std::make_pair(y, x));
        }
    }
    q.push(std::make_pair(0, 0));
    c[0] = 0;
    while (!q.empty()) {
        auto e = q.top();
        q.pop();
        for (int j = 0; j < g[e.second].size(); j++) {
            if (c[g[e.second][j].second] < g[e.second][j].first) {
                continue;
            }
            if (c[e.second]+g[e.second][j].first < c[g[e.second][j].second]) {
                c[g[e.second][j].second] = c[e.second]+g[e.second][j].first;
                q.push(g[e.second][j]);
            }
        }
    }
    for (int i = 0; i < n; i++) {
        std::cout << i << " " << c[i] << std::endl;
    }
}