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()

	route := make([][]Node, n)
	weight := make([]int, n)
	for i := 0; i < n; i++ {
		weight[i] = NIL
	}

	for i := 0; i < n; i++ {
		u := scanInt()
		k := scanInt()
		route[i] = make([]Node, k)
		for j := 0; j < k; j++ {
			route[u][j] = Node{id: scanInt(), weight: scanInt()}
		}
	}

	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 _, nextNode := range route[node.id] {
			if weight[nextNode.id] != NIL {
				continue
			}
			nextNode.weight += node.weight
			heap.Push(h, nextNode)
		}
	}

	for i, w := range weight {
		fmt.Println(i, w)
	}
}

C++: // 単一始点最短経路 ( ダイクストラ法 : 優先度付きキュー )
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>

#include<queue>

using namespace std;

static const int MAX_N = 10000;
static const int INFTY = (1 <<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

class q_element
{
    public:
        // 各頂点のNo.と経路の値
        int vertex_num;
        int vertex_val;

        // コンストラクタ
        q_element(int a, int b)
        {
            vertex_num = a;
            vertex_val = b;
        };
};

// ">" のオーバーロード [ receive_val ] を基準に大小比較を行う
bool operator> (const q_element &q_element_1, const q_element &q_element_2)
{
    return q_element_1.vertex_val > q_element_2.vertex_val;
};

// q_elementクラスのオブジェクトを昇順にするためのキューの定義
std::priority_queue< q_element,
                     std::vector<q_element>,
                     std::greater<q_element> > pqEle;

// 隣接リストを作成する ( 頂点と重みの情報を格納する )
vector<q_element> v_Link[MAX_N + 1];

int n;

// ダイクストラ法を実施するメソッド( 優先度付きキュー )
int Dijkstra_priority_queue();

int main(void)
{

    cin >> n;

    int k, c, u, v;
    q_element q_entity(0, 0);

    for(int i = 0; i < n; i++)
    {
        cin >> u >> k;

        for(int j = 0; j < k; j++)
        {
            cin >> v >> c;

            // 隣接リストの作成
            q_entity.vertex_num = v;
            q_entity.vertex_val = c;

            v_Link[u].push_back(q_entity);
        }
    }

    // 優先度付きキューを用いたダイクストラ法
    Dijkstra_priority_queue();

    return 0;

}

// 優先度付きキューを用いたダイクストラ法を実施するメソッド
int Dijkstra_priority_queue()
{
    int u, v, minv;
    int d[MAX_N], p[MAX_N], color[MAX_N];

    for(int i = 0; i < n; i++)
    {
        d[i] = INFTY;
        p[i] = -1;
        color[i] = WHITE;
    }

    // 初期値の設定
    d[0] = 0;
    color[0] = GRAY;
    // キューに要素を入れる
    pqEle.push( q_element(0, 0) );

    while( !pqEle.empty() )
    {
        //minv = INFTY;
        // 次に移動するべき頂点
        //u = -1;

        // 最小の値を持つ要素を取り出す ( キューの先頭 )
        u = pqEle.top().vertex_num;
        minv = pqEle.top().vertex_val;
        pqEle.pop();

        // 訪問完了
        color[u] = BLACK;

        for(int v_num = 0; v_num < v_Link[u].size(); v_num++)
        {
            // 隣接リストから要素を取得する
            v = v_Link[u][v_num].vertex_num;

            if( color[v] != BLACK )
            {
                // u → v の経路の中で, vのコストが最小のものが見つかれば更新する
                if( d[v] > d[u] + v_Link[u][v_num].vertex_val )
                {
                    // コストの記録
                    d[v] = d[u] + v_Link[u][v_num].vertex_val;
                    // 頂点 v の親を記録する
                    p[v] = u;
                    // 訪問状態の記録
                    color[v] = GRAY;

                    // キューに要素を入れる
                    pqEle.push( q_element(v, d[v]) );
                }
            }
        }
    }

    // 結果の表示
    for(int i = 0; i < n; i++)
    {
        cout << i << " " << ( d[i] == INFTY ? -1 : d[i] ) << endl;
    }

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define MAX 10000000000
#define INF INT_MAX

pair<int, int> A[2000000];
int size;

void heapIncreaseKey(int i, pair<int, int> key){
  if(key.first < A[i].first)
    assert(false);
  A[i] = key;
  while(i > 1 && A[i/2].first < A[i].first){
    swap(A[i].first, A[i/2].first);
    i = i/2;
  }
}

void maxHeapInsert(pair<int, int> key){
  size++;
  A[size].first = -INF;
  heapIncreaseKey(size, key);
}
void maxHeapify(ll i){
  int l = i*2;
  int r = i*2+1;
  int largest;
  if(l <= size && A[l].first > A[i].first)
    largest = l;
  else
    largest = i;
  if(r <= size && A[r].first > A[largest].first)
    largest = r;
  if(largest != i){
    swap(A[i], A[largest]);
    maxHeapify(largest);
  }
}
P heapExtractMax(){
  if(size < 1){
    assert(false);
  }
  pair<int, int> maxv = A[1];
  A[1] = A[size];
  size--;
  maxHeapify(1);
  return maxv;
}

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n; cin >> n;

  vector< vector< P > > f(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;
      f[u].push_back(make_pair(v, c));
    }
  }

  //priority_queue< P, vector<P>, greater<P> > que;
  vector<ll> d(n, MAX);
  d[0] = 0;
  //que.push(make_pair(0, 0));
  maxHeapInsert(make_pair(0, 0));

  while(size != 0){
    P q = heapExtractMax();
    if(q.first > d[q.second]) continue;
    
    for(int i = 0; i < f[q.second].size(); i++){
      if(d[ f[q.second][i].first ] > d[q.second] + f[q.second][i].second){
        d[ f[q.second][i].first ] = d[q.second] + f[q.second][i].second;
        maxHeapInsert(make_pair(d[ f[q.second][i].first ], f[q.second][i].first));
      }
    }
  }

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

  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
static const int MAX = 10000;
static const int INFTY = (1 << 20);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;
vector< pair <int, int> > adj[MAX];

void dijkstra()
{
    priority_queue< pair <int, int> > PQ;
    int color[MAX];
    int d[MAX];
    for (int i = 0; i < n; i++)
    {
        d[i] = INFTY;
        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;
        }

        for (int j = 0; j < adj[u].size(); j++)
        {
            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;
                PQ.push(make_pair(d[v] * (-1), v));
                color[v] = GRAY;
            }
        }
    }

    for (int i = 0; i < n; i++)
    {
        cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
    }
}

int main()
{
    int k, u, v, c;

    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> u >> k;
        for (int j = 0; j < k; j++)
        {
            cin >> v >> c;
            adj[u].push_back(make_pair(v, c));
        }
    }
    dijkstra();
    return 0;
}