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 <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;
}