Go: package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

const NIL = -1

type Node struct {
	id     int
	weight int
}

func init() {
	sc.Split(bufio.ScanWords)
}

type NodeHeap []Node

func (h NodeHeap) Len() int           { return len(h) }
func (h NodeHeap) Less(i, j int) bool { return h[i].weight < h[j].weight }
func (h NodeHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *NodeHeap) Push(x interface{}) {
	*h = append(*h, x.(Node))
}

func (h *NodeHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()

	list := make([][]int, n)
	weight := make([]int, n)
	for i := range list {
		list[i] = make([]int, n)
		weight[i] = NIL
		for j := range list[i] {
			list[i][j] = NIL
		}
	}

	for i := 0; i < n; i++ {
		u := scanInt()
		k := scanInt()
		for j := 0; j < k; j++ {
			v := scanInt()
			w := scanInt()
			list[u][v] = w
		}
	}

	start := Node{id: 0, weight: 0}
	h := &NodeHeap{start}
	heap.Init(h)

	for h.Len() > 0 {
		node := heap.Pop(h).(Node)
		if weight[node.id] != NIL {
			continue
		}
		weight[node.id] = node.weight

		for i, w := range list[node.id] {
			if w == NIL {
				continue
			}
			heap.Push(h, Node{id: i, weight: w + node.weight})
		}
	}

	w := bufio.NewWriter(os.Stdout)
	for i := 0; i < n; i++ {
		fmt.Fprint(w, i)
		fmt.Fprint(w, " ")
		fmt.Fprint(w, weight[i])
		fmt.Fprintln(w)
	}
	w.Flush()
}

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