Go: package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)

	g := makeGraph(n)
	for i := 0; i < n; i++ {
		u := getNextInt(scanner)
		k := getNextInt(scanner)
		for ii := 0; ii < k; ii++ {
			v := getNextInt(scanner)
			c := getNextInt(scanner)
			g[u][v] = c
		}
	}

	ans := make([]int, n)
	im := make(IntMap, 1)
	im.increment(0)
	for len(im) < n {
		min := 1 << 30
		x := -1
		for u := range im {
			for v := 0; v < n; v++ {
				if im.get(v) != 0 {
					continue
				}
				if min > ans[u]+g[u][v] {
					min = ans[u] + g[u][v]
					x = v
				}
			}
		}
		im.increment(x)
		ans[x] = min
	}

	for i := 0; i < n; i++ {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d", i, ans[i]))
	}
	writer.Flush()
}

func makeGraph(n int) [][]int {
	g := make([][]int, n)
	for i := 0; i < n; i++ {
		g[i] = make([]int, n)
		for ii := 0; ii < n; ii++ {
			g[i][ii] = 1 << 30
		}
	}

	return g
}

// IntMap ...
type IntMap map[int]int

func (m IntMap) get(key int) int {
	if _, ok := m[key]; ok {
		return m[key]
	}
	return 0
}
func (m IntMap) increment(key int) {
	if _, ok := m[key]; ok == false {
		m[key] = 0
	}
	m[key]++
}

C++: //Single Source Shortest Path I
#include <iostream>
#include <vector>
#include <climits>

using namespace std;

static const int N = 100;
static const int WHITE = 0;
static const int BLACK = 1;
//int colors[N], d[N];
//
//void dijkstra(vector<vector<int>> &W, int n) {
//    int u, mind;
//    for(int i = 0; i < n; i++) {
//        colors[i] = WHITE;
//        d[i] = INT_MAX;
//    }
//    d[0] = 0;
//    while(1) {
//        u = -1;
//        mind = INT_MAX;
//        for(int i = 0; i < n; i++) {
//            if(colors[i] == WHITE && d[i] < mind) {
//                u = i;
//                mind = d[i];
//            }
//        }
//        if(u == -1) break;
//        colors[u] = BLACK;
//        for(int i = 0; i < n; i++) {
//            if(W[u][i] != -1) {
//                d[i] = min(d[i], mind + W[u][i]);
//            }
//        }
//    }
//}
int d[N];

void dijkstra(vector<vector<int>> &W, int n) {
    int colors[n];
    for(int i=0; i<n; i++) {
        colors[i] = WHITE;
        d[i] = INT_MAX;
    }
    
    d[0] = 0;

    while(1) {
        int u = -1;
        int min_distance = INT_MAX;
        for(int i=0; i<n; i++) {
            if(colors[i] == BLACK) continue;
            if(d[i] < min_distance) {
                u = i;
                min_distance = d[i];
            }
        }
        if(u == -1) break;

        colors[u] = BLACK;
        for(int i=0; i<n; i++) {
            if(colors[i] == BLACK) continue;
            if(W[u][i] == -1) continue;
            d[i] = min(d[i], d[u] + W[u][i]);
        }
    }
}

int main() {
    int n;
    int u, k, v, c;
    cin >> n;
    vector<vector<int>> W(n, vector<int>(n));
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            W[i][j] = -1;
    for(int i = 0; i < n; i++) {
        cin >> u >> k;
        for(int j = 0; j < k; j++) {
            cin >> v >> c;
            W[u][v] = c;
        }
    }

    dijkstra(W, n);

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

C++: #include<iostream>

using namespace std;
static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

void dijkstra() {
    int minv;
    int d[MAX], color[MAX];
    
    for (int i = 0; i < n; i++) {
        d[i] = INFTY;
        color[i] = WHITE;
    }
    
    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;
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            M[i][j] = INFTY;
        }
    }
    
    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;
}

C++: #include <iostream>
#include <vector>
using namespace std;

typedef struct NODE {
    int id;
    int degree;
    int min_cost;
    bool done;
    vector<int> adj_n;
    vector<int> cost_to_n;
} node;

node **nodes;
int n;

node *gen_node(int id, int degree, vector<int> adj_n, vector<int> cost_to_n) {
    node *p = (node *)malloc(sizeof(node));
    p->id = id;
    p->degree = degree;
    if (id != 0) {
        p->min_cost = 100010;
    } else {
        p->min_cost = 0;
    }

    p->done = false;
    p->adj_n = adj_n;
    p->cost_to_n = cost_to_n;
    return p;
}

void solve() {
    for (int i = 0; i < n; i++) {
        node *src = (node *)malloc(sizeof(node));
        src = nodes[i];
        for (int j = 0; j < src->degree; j++) {
            node *dst = (node *)malloc(sizeof(node));
            dst = nodes[src->adj_n[j]];

            // 最小コストの更新
            //cout << "src: " << src->id << " dst: " << dst->id;
            //cout << " dst's min cost: " << dst->min_cost << " src's cost to dst: " << src->min_cost + src->cost_to_n[j] << endl;
            dst->min_cost = min(dst->min_cost, src->min_cost + src->cost_to_n[j]);

            // // dstの隣接nodeからsrcを消す処理
            // auto itr = find(dst->adj_n.begin(), dst->adj_n.end(), src->id);
            // int erase_index = itr - dst->adj_n.begin();
            // dst->degree--;
            // dst->adj_n.erase(dst->adj_n.begin() + erase_index);
            // dst->cost_to_n.erase(dst->cost_to_n.begin() + erase_index);
        }
    }
}

void print_node() {
    for (int i = 0; i < n; i++) {
        cout << nodes[i]->id << " " << nodes[i]->min_cost << endl;
    }
}

int main() {
    int u, k;
    cin >> n;

    nodes = (node **)malloc(sizeof(node) * n);

    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        vector<int> adj_n;
        vector<int> cost_to_n;

        int node_tmp;
        int cost_tmp;
        for (int j = 0; j < k; j++) {
            cin >> node_tmp >> cost_tmp;
            adj_n.push_back(node_tmp);
            cost_to_n.push_back(cost_tmp);
        }
        node *p = gen_node(u, k, adj_n, cost_to_n);
        nodes[u] = p;
    }

    solve();
    solve();

    print_node();

    return 0;
}