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;

#define MAX_SIZE 110
#define INF (1<<30)
#define NOT_VISITED 0
#define VISITED 1
#define COMPLETE 2

int n, G[MAX_SIZE][MAX_SIZE];
int d[MAX_SIZE], status[MAX_SIZE];

void dijkstra() {
    for (int i = 0; i < n; i++) {
        d[i] = INF;
        status[i] = NOT_VISITED;
    }
    d[0] = 0;

    int u, min_cost;
    while (1) {
        u = -1;
        min_cost = INF;
        for (int i = 0; i < n; i++) {
            if (min_cost > d[i] && status[i] != COMPLETE) {
                u = i;
                min_cost = d[i];
            }
        }
        if (u == -1) break;
        status[u] = COMPLETE;
        for (int i = 0; i < n; i++) {
            if (status[i] == COMPLETE || G[u][i] == INF) continue;
            if (d[i] > d[u] + G[u][i]) {
                d[i] = d[u] + G[u][i];
                status[i] = VISITED;
            }
        }
    }
    
    return;
}

void print() {
    for (int i = 0; i < n; i++) {
        cout << i << " ";
        if (d[i] == INF) cout << -1;
        else cout << d[i];
        cout << endl;
    }
    return;
}

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

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

    dijkstra();

    print();

    return 0;
}

C++: #include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;

#define dump(x) cerr << #x << " : " << x << '\n'
#define MOD(x, y) (((y) + (x) % (y)) % (y))

int N;

int main(int argc, char* argv[])
{
	using COST_T = ll;
	using NODE_T = int;
	using PAIR_T = pair<COST_T, NODE_T>;

	struct Edge
	{
		NODE_T node;
		COST_T cost;
	};

	const int MAX_NODE_INDEX = 99;
	const COST_T INF_DIST = linf;
	vector<Edge> edges[MAX_NODE_INDEX + 1];
	COST_T dist_ar[MAX_NODE_INDEX + 1];

	scanf("%d", &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);
			edges[u].push_back( { v, c } );
		}
	}

	priority_queue<PAIR_T, vector<PAIR_T>, greater<PAIR_T>> pq;
	fill(dist_ar, dist_ar + MAX_NODE_INDEX + 1, INF_DIST);
	NODE_T st = 0;
	dist_ar[st] = 0;
	pq.push(PAIR_T(0, st));
	while(!pq.empty()) {
		COST_T temp_cost = pq.top().first;
		NODE_T node_index = pq.top().second;
		pq.pop();
		if (dist_ar[node_index] < temp_cost) continue;
		for (int next_list_index = 0; next_list_index < (int)edges[node_index].size(); next_list_index++) {
			COST_T new_cost = temp_cost + edges[node_index][next_list_index].cost;
			NODE_T next_index = edges[node_index][next_list_index].node;
			if (dist_ar[next_index] >= new_cost) {
				dist_ar[next_index] = new_cost;
				pq.push(PAIR_T(new_cost, next_index));
			}
		}
	}

	for (int i = 0; i < N; i++) {
		printf("%d %lld\n", i, dist_ar[i]);
	}

	return 0;
}

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 color[MAX], d[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) {
  	      	  minv = d[i];
  	      	  u = 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][i] = 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 <iostream>
#include <string>
#include <sstream>
#include <limits>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>

using namespace std;

// 隣接リストを用いたグラフ構造
template <typename Vertex, typename Edge>
struct Graph
{
	// 頂点
	vector<Vertex> vertices;
	// 第i頂点を始点とする有向辺の終点
	vector<unordered_map<int, Edge>> edges;

	// n個の頂点を事前に生成する
	void resize (size_t n)
	{
		vertices.resize(n);
		edges.resize(n);
	}

	// 頂点n個分のメモリ領域を事前に確保する
	void reserve (size_t n)
	{
		vertices.reserve(n);
		edges.reserve(n);
	}

	// 位数（頂点数）
	size_t order ()
	{
		return vertices.size();
	}

	// サイズ（辺の数）
	size_t size ()
	{
		return accumulate(edges.begin(), edges.end(), static_cast<size_t>(0), [](size_t sum, unordered_map<int, Edge> &edge){ return sum + edge.size(); });
	}

	// 頂点を追加する
	void addVertex (const Vertex &vertex)
	{
		vertices.push_back(vertex);
		edges.emplace_back();
	}

	// 有向辺を追加する
	void addEdge (int from, int to, const Edge &edge)
	{
		edges[from][to] = edge;
	}

	// 有向辺を削除する
	void removeEdge (int from, int to)
	{
		edges[from].erase(to);
	}
};

// 使用例（Dijkstra法）
struct Dijkstra : public Graph<nullptr_t, int>
{
	vector<int> weight;

	void dijkstra (int from)
	{
		weight.resize(order());
		fill(weight.begin(), weight.end(), numeric_limits<int>::max());

		auto compare = [this] (int l, int r) { return weight[l] > weight[r]; };
		priority_queue<int, vector<int>, decltype(compare)> fixed(compare);

		weight[from] = 0;
		fixed.push(from);

		while (!fixed.empty())
		{
			int vertex = fixed.top();
			fixed.pop();

			// to = { first: dest_index, second: edge_weight }
			for (auto to : edges[vertex])
			{
				if (weight[to.first] <= weight[vertex] + to.second) continue;

				weight[to.first] = weight[vertex] + to.second;
				fixed.push(to.first);
			}
		}
	}
};

int main ()
{
	int n; cin >> n;

	Dijkstra dijkstra;
	dijkstra.resize(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;

			dijkstra.addEdge(u, v, c);
		}
	}

	dijkstra.dijkstra(0);

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

	return 0;
}