Go: package main

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

//make priority queue
type Item struct {
	id       int
	priority int // this state is priority and distans from start
	index    int
}

type PriorityQueue []*Item

func (pq PriorityQueue) Len() int { return len(pq) }

// we want the ascending-priority-queue.
// So we use less than here.
func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].priority < pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = j
	pq[j].index = i
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	item.index = -1 //for safety
	*pq = old[0 : n-1]
	return item
}

func (pq *PriorityQueue) update(dist int, id int) {
	for _, i := range *pq {
		if i.id == id {
			if i.priority > dist {
				i.priority = dist
			}
		}
	}
}

// the main code
func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

func dikstra(dist *[][]int, n int) *[]int {
	// preparate priority queue
	inf := 1 << 30
	pq := make(PriorityQueue, n)
	shortests := make([]int, n)
	for i := 0; i < n; i++ {
		pq[i] = &Item{
			id:       i,
			priority: inf,
			index:    i,
		}

		shortests[i] = inf
	}
	pq[0].priority = 0
	shortests[0] = 0
	heap.Init(&pq)

	for pq.Len() > 0 {
		item := heap.Pop(&pq).(*Item)
		shortests[item.id] = item.priority
		for id, d := range (*dist)[item.id] {
			if d != -1 {
				pq.update(item.priority+d, id)
			}
		}
		heap.Init(&pq)
	}
	return &shortests
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	// init
	n := nextInt(sc)
	dist := make([][]int, n)
	for i := 0; i < n; i++ {
		dist[i] = make([]int, n)
		for j := 0; j < n; j++ {
			dist[i][j] = -1
		}
	}

	// std Input
	for i := 0; i < n; i++ {
		u := nextInt(sc)
		k := nextInt(sc)
		for j := 0; j < k; j++ {
			v, c := nextInt(sc), nextInt(sc)
			dist[u][v] = c
		}
	}

	shortests := dikstra(&dist, n)
	for i, d := range *shortests {
		fmt.Printf("%d %d\n", i, d)
	}
}

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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
// #define SORT(v, n) stable_sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const int MAX   = 10000;
const int INF   = (1 << 20);
const int white = 0;
const int gray  = 1;
const int black = 2;

int                    n;
vector<pair<int, int>> adj[MAX];  // 重み付き有向グラフの隣接リスト表現

int dijkstra() {
    priority_queue<pair<int, int>> pq;
    int                            d[MAX], color[MAX];
    rep(i, n) {
        d[i]     = INF;
        color[i] = white;
    }

    d[0] = 0;
    pq.push(make_pair(0, 0));
    color[0] = gray;

    while (!pq.empty()) {
        pair<int, int> f = pq.top();
        pq.pop();
        int u    = f.second;
        color[u] = black;

        // 最小値を取り出し、それが最短でなければ無視
        if (d[u] < f.first * (-1)) continue;

        rep(j, adj[u].size()) {
            int v = adj[u][j].first;
            if (color[v] == black) continue;
            if (d[v] > d[u] + adj[u][j].second) {
                d[v] = d[u] + adj[u][j].second;
                // priority_queueはデフォルトで大きい値を優先するため-1を掛ける。
                pq.push(make_pair(d[v] * (-1), v));
                color[v] = gray;
            }
        }
    }
    rep(i, n) { cout << i << " " << (d[i] == INF ? -1 : d[i]) << endl; }
}

// 単一始点最短経路 part2
// 二分ヒープ(優先度付きキュー）
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // cout << fixed << setprecision(5);

    int k, c, u, v;
    cin >> n;
    rep(i, n) {
        cin >> u >> k;
        rep(j, k) {
            cin >> v >> c;
            adj[u].push_back(make_pair(v, c));
        }
    }

    dijkstra();

    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<utility>
#include<limits>
using namespace std;
typedef pair<int, int> Edge;
int main()
{
	int n; cin >> n;
	vector< vector< Edge > > lists;

	for (int i = 0; i < n; i++)
	{
		vector<Edge> list;
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; j++)
		{
			Edge edge;
			cin >> edge.second >> edge.first;
			list.push_back(edge);
		}
		lists.push_back(list);
	}

	vector<int> costs(n, -1);
	costs[0] = 0;
	priority_queue<Edge> queue;
	for (Edge edge : lists[0])
		queue.push(edge);

	while (!queue.empty())
	{
		Edge edge = queue.top(); queue.pop();
		int dest = edge.second;
		int cost = edge.first;
		if (costs[dest]!=-1 && costs[dest] < cost)continue;
		int new_cost = costs[edge.second] = edge.first;

		for (Edge next : lists[dest])
		{
			next.first += new_cost;
			if(costs[next.second]>next.first||costs[next.second]==-1)
				queue.push(next);
		}
	}
	for (int i = 0; i < n; i++)
		cout << i << " " << costs[i] << endl;

	char c;
	cin >> c;

	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <queue>
using namespace std;
const int INF = 1 << 30;
const int NIL = 0;
const int MAXN = 10005;
int vis[MAXN];
int d[MAXN];
int head[500005];
int n;
int cnt;
struct Edge {
	int to, next, w;
	Edge() {}
} edge[500005];

void add(int u, int v, int w)
{
	edge[cnt].to = v;
	edge[cnt].w = w;
	edge[cnt].next = head[u];
	head[u] = cnt++;
}

struct Node {
	int u, w;
	Node (int _u, int _w) :u(_u), w(_w) {}
	friend bool operator<(const Node& a, const Node& b)
	{
		return a.w > b.w;
	}
};

void dijkstra(int s)
{
	priority_queue<Node> q;
	for (int i = 0; i < n; ++i)
		d[i] = INF, vis[i] = false;
	d[s] = 0;
	
	Node t(s, 0);
	q.push(t);
	int u, v, w;
	int count = 0;
	while (!q.empty() && count < n - 1)
	{
		t = q.top();
		q.pop();
		u = t.u;
		if (d[u] < t.w)
			continue;
		vis[u] = true;
		++count;
		for (int i = head[u]; i != NIL; i = edge[i].next)
		{
			v = edge[i].to;
			w = edge[i].w;
			if (!vis[v] && d[v] > d[u] + w)
			{
				d[v] = d[u] + w;
				q.push(Node(v, d[v]));
			}
		}
	}
	if (count == n - 1)
		for (int i = 0; i < n; ++i)
			cout << i << " " << d[i] << endl;

}

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int k, s, e, w;
	cin >> n;
	//memset(head, NIL, sizeof(-1));
	cnt = 1;
	for (int i = 0; i < n; ++i)
	{
		cin >> s >> k;
		while (k--)
		{
			cin >> e >> w;
			add(s, e, w);
		}
	}
	dijkstra(0);

	return 0;
}