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++: // ALDS1_12_B: Single Shortest Path I
#include <iostream>
#include <vector>
#include <algorithm>
#define INF 1000000
#define NIL -1
using graph = std::vector<std::vector<int>>;
bool debug = false;

graph adjacency_matrix;
std::vector<bool> node_stat;
std::vector<int> next_node, minimum_cost;

void dijkstra(int vertex) {
    if (debug) std::cout << "dijkstra(" << vertex << ")\n";
    node_stat.at(vertex) = false;

    for (int i=0; i<adjacency_matrix.at(vertex).size(); i++) {
        int next_vertex = i, edge_weight = adjacency_matrix.at(vertex).at(next_vertex);
        if (edge_weight != -1) {
            int cost_to_next = minimum_cost.at(vertex) + edge_weight;
            if (cost_to_next < minimum_cost.at(next_vertex)) {
                if (debug) std::cout << vertex << " -> " << next_vertex << ": " << cost_to_next << "\n";
                minimum_cost.at(next_vertex) = cost_to_next;
                next_node.at(vertex) = next_vertex;
            }
        }
    }

    int min_weight = INF, next_vertex = NIL;
    for (int i=0; i<minimum_cost.size(); i++) {
        if (minimum_cost.at(i) < min_weight) {
            if (node_stat.at(i)) {
                if (debug) std::cout << "i = " << i << "\n";
                min_weight = minimum_cost.at(i);
                next_vertex = i;
            }   
        }
    }
    if (debug) std::cout << "min_weight = " << min_weight << ", next_vertex = " << next_vertex << "\n";
    if (next_vertex == NIL) {
        return;
    }
    dijkstra(next_vertex);
}

void init() {
    node_stat.assign(node_stat.size(), true);
    next_node.assign(next_node.size(), NIL);
    minimum_cost.assign(minimum_cost.size(), INF);
    minimum_cost.at(0) = 0;
}

int main() {
    int total_node_num; std::cin >> total_node_num;
    
    adjacency_matrix.resize(total_node_num);
    for (int i=0; i<adjacency_matrix.size(); i++) adjacency_matrix.at(i).assign(total_node_num, NIL);
    node_stat.resize(total_node_num);
    next_node.resize(total_node_num);
    minimum_cost.resize(total_node_num);
    
    for (int i=0; i<total_node_num; i++) {
        int vertex_num; std::cin >> vertex_num;
        int outdegree; std::cin >> outdegree;
        for (int j=0; j<outdegree; j++) {
            int next_vertex; std::cin >> next_vertex;
            std::cin >> adjacency_matrix.at(vertex_num).at(next_vertex);
        }
    }
    init();
    dijkstra(0);
    for (int i=0; i<minimum_cost.size(); i++) {
        std::cout << i << " " << minimum_cost.at(i) << "\n";
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

#define MAX 100
#define INFTY (1 << 21)
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[MAX][MAX], d[MAX], color[MAX];

void shortestPath(int s){
    int u, minv;
    //距離を初期化
    for(int i = 0; i < n; i++){
        d[i] = INFTY;
        color[i] = WHITE;
    }

    d[s] = 0;

    while(1){
        int u = -1;
        int minv = INFTY;
        //最も距離が近いものを更新
        for(int i = 0; i < n; i++){
            if(color[i] != BLACK && d[i] < INFTY){
                if(d[i] < minv){
                    u = i;
                    minv = d[i];
                }
            }
        }

        if(u == -1) break;
        color[u] = BLACK;

        for(int v = 0; v < n; v++){
            d[v] = min(d[v], d[u] + M[u][v]);
        }
    }
}

int main(){
    cin >> n;
    //隣接行列を作製

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

    shortestPath(0);

    rep(i,n){
        cout << i << " " << d[i] << endl;
    }

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define rep(i, n) REP(i, 0, n)
#define REP(i,k,n) for(int i = k; i < n; i++)
#define mmax(start, end) *max_element(start, end)
#define mmin(start, end) *min_element(start, end)
#define argmax max_element
#define argmin min_element
#define push push_back
#define pop pop_back
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef string str;

int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

template<class T = ll> T in() {
    T _in;
    cin >> _in;
    return _in;
}

#define EMAX 10000000

int cost[101][101];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n=in();
    ll d[101];

    rep(i, n) {
        rep(j, n) {
            cost[i][j] = EMAX;
        }
        d[i] = EMAX;
    }

    rep(i, n) {
        int u=in<int>(), k=in<int>();
        rep(j, k) {
            int v=in<int>(), c=in<int>();
            cost[u][v] = c;
        }
    }

    // ノード0からの距離を調べる
    d[0] = 0;
    bool flag = true;
    while(flag) {
        flag=false;
        // 移動する方法のある全ノードからの，次のノードへの移動コストを考える
        rep(i, n) {
            if(d[i] != EMAX) {
                rep(j, n) {
                    if(i == j)
                        continue;
                    int next_c = d[i] + cost[i][j];

                    // 更新できる場合更新
                    if(d[j] > next_c) {
                        d[j] = next_c;
                        flag=true;
                    }
                }
            }
        }
    }

    rep(i, n) {
        cout << i << " " << d[i] << endl;
        // rep(j, n) {
        //     cout << cost[i][j] << " ";
        // }
        // cout << endl;
    }
    
    return 0;
}

C++: #include<iostream>
#include<vector>
#define N 101
using namespace std;
int n;
vector<int> D(N,1<<30);
//bool visited[N];
vector<bool> visited(N,0);
vector<int> pre(N,0);
vector<vector<int>> M(N,vector<int>(N,0));
//int M[N][N];

void dijkstra(){
    D[0]=0;
    pre[0]=-1;

    while(1){
        int minD=1<<30;
        int u=-1;
        for(int i=0;i<n;i++){
            if(visited[i]) continue;
            if(D[i]<minD){
                u=i;
                minD=D[i];
            }
        }
        if(u==-1) break;

        visited[u]=1;
        for(int i=0;i<n;i++){
            if(visited[i]) continue;
            if(M[u][i]>0 && D[i]>D[u]+M[u][i]){
                D[i]=D[u]+M[u][i];
                pre[i]=u;
            }
        }

    }
}

void init(){
    cin>>n;
    int u,k,c,v;
    for(int i=0;i<n;i++){
        /*for(int j=0;j<n;j++){
            M[i][j]=0;
        }*/
        visited[i]=false;
        cin>>u>>k;
        for(int j=0;j<k;j++){
            cin>>v>>c;
            M[u][v]=c;
        }
    }
}

int main(){
    init();
    /*for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cout<<M[i][j]<<' ';
        }
        cout<<endl;
    }*/
    dijkstra();
    for(int i=0;i<n;i++){
        cout<<i<<' '<<D[i]<<endl;
    }
    return 0;
}

/*
5
0 3 2 3 3 1 1 2
1 2 0 2 3 4
2 3 0 3 3 1 4 1
3 4 2 1 0 1 1 4 4 3
4 2 2 1 3 3
*/