Go: package main

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

type Item struct {
	value    int // The value of the item; arbitrary.
	priority int // The priority of the item in the queue.
	// The index is needed by update and is maintained by the heap.Interface methods.
	index int // The index of the item in the heap.
}
type PriorityQueue []*Item

func (pq PriorityQueue) Len() int { return len(pq) }
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 = i
	pq[j].index = j
}
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
}

type Q struct {
	pq *PriorityQueue
	ds map[int]int // It has always same value as pq. For random access.
}

func newQ() *Q {
	pq := new(PriorityQueue)
	heap.Init(pq)
	return &Q{
		pq: pq,
		ds: make(map[int]int),
	}
}
func (q *Q) pop() (u, d int) {
	item := heap.Pop(q.pq).(*Item)
	delete(q.ds, item.value)
	return item.value, item.priority
}
func (q *Q) get(u int) (int, bool) { // returns d
	d, ok := q.ds[u]
	return d, ok
}
func (q *Q) set(u, d int) {
	q.ds[u] = d
	for _, item := range *q.pq {
		if item.value != u {
			continue
		}

		item.priority = d
		heap.Fix(q.pq, item.index)
		return
	}
	heap.Push(q.pq, &Item{
		priority: d,
		value:    u,
	})
}
func (q *Q) len() int {
	return len(q.ds)
}

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 := newQ()
	q.set(0, 0)
	visited := make(map[int]struct{})
	out := make([]int, n)

	for q.len() > 0 {
		u, d := q.pop()
		for uu, c := range cs[u] {
			// Consider the connection between u and uu.
			if _, ok := visited[uu]; ok {
				continue
			}
			dd := d + c
			if d, ok := q.get(uu); !ok || d > dd {
				q.set(uu, dd)
			}
		}

		out[u] = d
		visited[u] = struct{}{}
	}

	for u, d := range out {
		fmt.Println(u, d)
	}
}

C++: #include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mkp make_pair
#define rep(i,n) for(int i=0; i<(n); ++i)
#define outl(x) cout << (x) << '\n'
#define FAST() cin.tie(0), ios::sync_with_stdio(false)
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, B b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, B b){return b<a ? a=b,1 : 0;}
#define INF 0x3f3f3f3f

int N;
vector <pii> G[101];
int mcos[101];

void dijkstra(int s)
{
   priority_queue < pii, vector<pii>, greater<pii> > pq;
   pq.push( mkp(0, s) );
   memset( mcos, INF, sizeof(mcos) );
   mcos[s] = 0;
   while( !pq.empty() ){
      const pii tmp = pq.top(); pq.pop();
      if( mcos[tmp.se] < tmp.fi )continue;
      for( const auto& v : G[tmp.se] ){
         const int nc = v.fi + tmp.fi;
         if( chmin( mcos[v.se], nc )) pq.push( mkp(nc, v.se) );
      }
   }
}

signed main()
{
   FAST();
   cin >> N;

   rep(i, N){
      int u, k, to, c;
      cin >> u >> k;
      while(k--){
         cin >> to >> c;
         G[i].pb( mkp(c,to) );
      }
   }
   dijkstra(0);
   rep(i, N) cout << i << ' ' << mcos[i] << '\n';
}

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 = 100;
static const int INFTY = (1 <<21);

static const int NO = 0;
static const int YES = 1;

// グラフ情報を保持する配列
int ary_graph[MAX_N + 1][MAX_N + 1];
// 辺の関係を保持する配列
vector<int> v_connection[MAX_N];
// スタートからの距離を保持する配列
int ary_distance[MAX_N + 1];
// 各頂点の状態を保持する配列 ( 確定 or 未確定 )
int ary_vertex[MAX_N];

void Dijkstra_Method(int start_v, int all_v);

int main(void)
{

    int n, u, k, v, c;

    for(int i = 0; i < MAX_N + 1; i++)
    {
        ary_vertex[i] = NO;

        // 全頂点のスタートからの距離を無限大とする
        ary_distance[i] = INFTY;

        for(int j = 0; j < MAX_N + 1; j++)
        {
            // 配列の初期化
            ary_graph[i][j] = INFTY;
        }
    }

    cin >> n;

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

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

            // 隣接行列の設定
            ary_graph[u][v] = c;
            // 辺の関係の保存
            v_connection[u].push_back(v);
        }
    }

    Dijkstra_Method(0, n);

    // 結果の表示
    for(int i = 0; i < n; i++)
    {
        cout << i << " " << ary_distance[i] << endl;;
    }

    return 0;
}

// ダイクストラ法を実施する関数
// start_v : スタートする頂点のNo.
// all_v   : 全頂点の数
void Dijkstra_Method(int start_v, int all_v)
{
    int vertex_num = 0;
    int ele, confirm_v, tmp_distance;
    int min_distance, min_v;

    // スタート地点の距離はゼロとする
    ary_distance[start_v] = 0;
    // 確定した頂点を設定
    confirm_v = start_v;
    ary_vertex[confirm_v] = YES;

    // 全頂点のスタートからの距離が確定するまで, ループを継続する
    while( vertex_num != all_v )
    {

        min_v = INFTY;
        min_distance = INFTY;

        // 確定した頂点から, [直接つながっている] かつ [未確定]の頂点の距離を計算する
        for(int i = 0; i < v_connection[confirm_v].size(); i++)
        {
            // 辺のつながっている頂点No.
            ele = v_connection[confirm_v][i];

            // confirm_v の頂点を経由した場合の距離 ( 経由する頂点までの距離 + 辺の重み )
            tmp_distance = ary_distance[confirm_v] + ary_graph[confirm_v][ele];

            if( ary_vertex[ele] == NO )
            {
                // 未確定の頂点について検討する

                if( tmp_distance < ary_distance[ele] )
                {
                    // 最小値で距離情報を更新する
                    ary_distance[ele] = tmp_distance;
                }

                if( min_distance > tmp_distance )
                {
                    // confirm_v の頂点から, 最小距離の頂点を探す
                    min_distance = tmp_distance;
                    min_v = ele;
                }
            }
        }

        // 次に進むべき頂点の確定
        if( min_v != INFTY )
        {
            confirm_v = min_v;
            ary_vertex[confirm_v] = YES;
        }

        vertex_num++;

    }

    return;
}

C++: #include <iostream>
#include <queue>
#include <algorithm>
#include <vector>


using namespace std;

using ll = long long;

const ll MAX = 100;


ll edges[MAX][MAX];
bool finished[MAX] = {};
ll d[MAX];
ll n;


void dijkstra()
{
    priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;
    pq.push(make_pair(0, 0));

    while (!pq.empty()) {
        auto p = pq.top();
        pq.pop();

        if (finished[p.second])
            continue;

        for (ll i = 0; i < n; i++) {
            if (!(edges[p.second][i] > 0) || finished[i])
                continue;
            pq.push(make_pair(p.first + edges[p.second][i], i));
        }
        finished[p.second] = true;
        d[p.second] = p.first;
    }
}


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

    dijkstra();

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