Go: package main

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

func main() {
	r := bufio.NewReader(os.Stdin)

	var n int
	fmt.Fscan(r, &n)
	cs := make([]map[int]int, n) // []v_i -> c_i
	for h := 0; h < n; h++ {
		var u, k int
		fmt.Fscan(r, &u, &k)
		m := make(map[int]int)
		for i := 0; i < k; i++ {
			var v, c int
			fmt.Fscan(r, &v, &c)
			m[v] = c
		}

		cs[u] = m
	}

	q := make(map[int]int)
	q[0] = 0
	visited := make(map[int]struct{})
	out := make([]int, n)

	for len(q) > 0 {
		u := top(q)
		for uu, c := range cs[u] {
			// Consider the connection between u and uu.
			if _, ok := visited[uu]; ok {
				continue
			}
			if d, ok := q[uu]; !ok || d > q[u]+c {
				q[uu] = q[u] + c
			}
		}

		out[u] = q[u]
		delete(q, u)
		visited[u] = struct{}{}
	}

	for u, d := range out {
		fmt.Println(u, d)
	}
}

func top(q map[int]int) int {
	minu := -1
	min := -1
	for u, d := range q {
		if min < 0 || d < min {
			minu = u
			min = d
		}
	}

	return minu
}

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]; // d[n]は始点からnまでの最短コスト，color[v]はvの訪問状態

    for (int i = 0; i < n; i++) {
        // 最短コストと訪問状態の初期化
        d[i] = INFTY;
        color[i] = WHITE;
    }

    d[0] = 0; // 始点から始点までの最短コストは0
    color[0] = GRAY; // 始点を訪問済みにする
    while (1) {
        minv = INFTY; // 最小コストを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 (color[v] != BLACK && M[u][v] != INFTY) { // vに訪問済みでなくu->vへのコストがINFでないとき
                if (d[v] > d[u] + M[u][v]) { // 「vへの最小コスト」より「現在までのコストと現在地からvまでのコストを加えたもの」のほうが小さい時
                    d[v] = d[u] + M[u][v]; // vまでのコストを更新
                    color[v] = GRAY; // vへ訪問済みとする
                }
            }
        }
    }
    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 <utility>
#include <vector>
#include <queue>
using namespace std;
#define INF 2000000000
int Min(int x,int y){
        return x>y?y:x;
}
int main(){
        int N;
        cin >> N;
        vector <vector <int> > adjancent(N,vector <int>(N,INF));
        for(int i=0 ; i<N ; i++ ){
                int n,degree,to,cost;
                cin >> n >> degree;
                for(int l=0 ; l<degree ; l++ ){
                        cin >> to >> cost;
                        adjancent[n][to]=cost;
                }
        }
        vector<int> dp(N,INF);
        dp[0]=0;
        bool sign=true;
        while(sign){
                sign=false;
                for(int now=0 ; now<N ; now++){
                        for(int i=0 ; i<N ; i++ ){
                                int tmp=dp[i];
                                dp[i]=Min(dp[i],dp[now]+adjancent[now][i]);
                                if(tmp!=dp[i])
                                        sign=true;
                        }
                }
        }
        for(int i=0 ; i<N ; i++ )
                cout <<i<<" "<<dp[i]<<endl;
        return 0;
}

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

const long MAX = 100;
const long INFTY = (1<<21);
const long WHITE = 0;
const long GRAY = 1;
const long BLACK = 2;

long n, M[MAX][MAX];

void dijkstra(){
	long minv;
	long d[MAX], color[MAX];

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

	d[0] = 0;
	color[0] = GRAY;
	while (1){
		minv = INFTY;
		long u = -1;
		for (long 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 (long 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 (long i = 0; i < n; i++){
		cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
	}
}

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

	long k, c, u, v;
	for (long i = 0; i < n; i++){
		cin >> u >> k;
		for (long j = 0; j < k; j++){
			cin >> v >> c;
			M[u][v] = c;
		}
	}

	dijkstra();

	return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <list>
using namespace std;

#define NODE_NUM 100

class Node
{
private:
	int next_node_list[NODE_NUM];
	int next_node_num;
	int next_weight_list[NODE_NUM];
public:
	Node();
	void AddNextNode(int id, int weight);
	void SetWeight(int weight);
	void DistributeWeight();
	int weight_from_0;
	bool check;
};

Node::Node()
{
	next_node_num = 0;
	weight_from_0 = -1;
	check = false;
}

Node *Node_list;
list<int> Distributed_node_list;

void Node::AddNextNode(int id, int weight)
{
	next_node_list[next_node_num] = id;
	next_weight_list[next_node_num] = weight;
	next_node_num++;
}

void Node::SetWeight(int weight)
{
	if (weight_from_0 == -1 || weight < weight_from_0) {
		weight_from_0 = weight;
	}
}

void Node::DistributeWeight()
{
	check = true;
	for (int i = 0; i < next_node_num; i++) {
		if (Node_list[next_node_list[i]].check == false) {
			Distributed_node_list.push_back(next_node_list[i]);
			Node_list[next_node_list[i]].SetWeight(weight_from_0 + next_weight_list[i]);
		}
	}
}

int main(void)
{
	//input
	int n;
	cin >> n;
	Node_list = new Node[n]();
	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			int v, c;
			cin >> v >> c;
			Node_list[i].AddNextNode(v, c);
		}
	}

	//weight from 0 ?
	Node_list[0].SetWeight(0);
	Node_list[0].DistributeWeight();
	while (!Distributed_node_list.empty()) {
		int min_weight = Node_list[Distributed_node_list.front()].weight_from_0;
		list<int>::iterator min_idx = Distributed_node_list.begin();
		list<int>::iterator itr;
		for(itr = Distributed_node_list.begin(); itr != Distributed_node_list.end(); itr++){
			if (Node_list[*itr].weight_from_0 < min_weight) {
				min_weight = Node_list[*itr].weight_from_0;
				min_idx = itr;
			}
		}
		Node_list[*min_idx].DistributeWeight();
		Distributed_node_list.erase(min_idx);
	}
	
	//output
	for (int i = 0; i < n; i++) {
		cout << i << " " << Node_list[i].weight_from_0 << endl;
	}
	
	return 0;
}