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++: 
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner in = new Scanner(System.in);

		int u = in.nextInt();
		int[][] mat = new int[u][u];
		for (int i = 0; i < u; i++) {
			Arrays.fill(mat[i], -1);
		}
		for (int i = 0; i < u; i++) {
			int fromNode = in.nextInt();
			int toNodeCount = in.nextInt();
			for (int j = 0; j < toNodeCount; j++) {
				int toNode = in.nextInt();
				int edgeWeight = in.nextInt();
				mat[fromNode][toNode] = edgeWeight;
			}
		}

		// solve
		Set<Integer> x = new HashSet<>();
		Set<Integer> y = new HashSet<>();
		boolean[] visit = new boolean[u];
		for (int i = 1; i < u; i++) {
			y.add(i);
		}
		int[] nodeCost = new int[u];
		Arrays.fill(nodeCost, Integer.MAX_VALUE);
		x.add(0);
		nodeCost[0] = 0;
		visit[0] = true;

		while (!y.isEmpty()) {
			int min = Integer.MAX_VALUE;
			int v = -1;
			for (int from : x) {
				for (int to = 0; to < u; to++) {
					int visitCost = mat[from][to] + nodeCost[from];
					// toのノードが最小コストで訪問済でない場合
					if (mat[from][to] != -1 && !visit[to] && visitCost <= nodeCost[to]) {
						nodeCost[to] = visitCost;
						if (nodeCost[to] < min) {
							min = nodeCost[to];
							v = to;
						}
					}
				}
			}
			x.add(v);
			y.remove(v);
			visit[v] = true;
		}

		for (int i = 0; i < u; i++) {
			System.out.println(i + " " + nodeCost[i]);
		}
	}

}

C++: // ※注意t C++14でコンパイルしないとエラーがでます
// ダイクストラ法
// ALDS1_12_C http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_12_C&lang=jp
#include <bits/stdc++.h>
using namespace std;

struct Vertex {                       // 頂点の情報を構造体Vertexで表す
    vector<pair<int, int>> neighbor;  // 隣接する頂点とそこまでの距離
    bool fixed = false;               // この頂点が確定しているか否か
    int fixed_cost = 0;               // 確定したコスト（始点からの最短距離）
};

int main(void) {
    // ■■ 初期化・データの読み込み ■■ 　
    int n;
    cin >> n;
    Vertex vertexs[n];  // n個の頂点を用意する
    for(int i = 0; i < n; i++) {
        int v, k;  // v:頂点　　k:vに隣接する頂点の数
        cin >> v >> k;
        for(int j = 0; j < k; j++) {
            int vi, ci;
            cin >> vi >> ci;
            vertexs[v].neighbor.push_back(make_pair(ci, vi));  // 各頂点vに対して、（隣接する頂点までのコスト(距離) と　その隣接頂点 ）をneighbor に読み込む
        }
    }

    // ■■ ダイクストラ法を実行 ■■ 　
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> que;  // pair< 出発点からの頂点までのコスト , 頂点 > の値を持つpriority_queue　（greaterにしないと昇順にならない）
    que.push(make_pair(0, 0));
    while(!que.empty()) {
        int cost = que.top().first;
        int v = que.top().second;
        que.pop();
        if(vertexs[v].fixed == false) {
            vertexs[v].fixed = true;
            vertexs[v].fixed_cost = cost;
            for(int i = 0; i < int(vertexs[v].neighbor.size()); i++) {
                int vi = vertexs[v].neighbor[i].second;  // vi: 頂点vに隣接するi番目の頂点
                int ci = vertexs[v].neighbor[i].first;   // ci: 頂点vから頂点viまでのコスト
                if(vertexs[vi].fixed == false) {
                    que.push(make_pair(cost + ci, vi));
                }
            }
        }
    }

    for(int i = 0; i < n; i++) {
        cout << i << " " << vertexs[i].fixed_cost << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
#define INF 1000000000
#define MAX_N 10000
using namespace std;
int n;
int d[MAX_N];

struct edge {
	int to, cost;
	edge(int to_, int cost_) : to(to_), cost(cost_) {}
};
typedef pair<int, int> P;
vector<edge> G[MAX_N];

void Dijkstra(int start) {
	fill(d, d + n, INF);
	priority_queue<P, vector<P>, greater<P>> que;
	d[start] = 0;
	que.push(P(0, start));

	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.second;
		if (d[v] < p.first) continue;
		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

int main()
{
	cin >> n;
	for (int i = 0, u, k; i < n; i++) {
		cin >> u >> k;
		for (int j = 0, v, c; j < k; j++) {
			cin >> v >> c;
			G[u].push_back(edge(v, c));
		}
	}
	Dijkstra(0);
	for (int i = 0; i < n; i++) {
		cout << i << ' ' << d[i] << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<cstring>
#define P pair<int,int>//cost to
using namespace std;

vector<P>rinsetu[100];
int mincost[100];
signed main() {
	int a; cin >> a;
	for (int b = 0; b < a; b++) {
		int c, d; cin >> c >> d;
		for (int e = 0; e < d; e++) {
			int f, g; scanf("%d%d", &f, &g);
			rinsetu[c].push_back(P(g,f));
		}
	}
	fill(mincost, mincost + a, 1 << 29);
	mincost[0] = 0;
	priority_queue<P, vector<P>, greater<P>>Q;
	Q.push(P(0,0));
	while (Q.size()) {
		P t = Q.top(); Q.pop();
		if (t.first > mincost[t.second])continue;
		for (P i : rinsetu[t.second]) {
			if (mincost[i.second] > t.first + i.first) {
				mincost[i.second] = t.first + i.first;
				Q.push(P(t.first + i.first,i.second));
			}
		}
	}
	for (int i = 0; i < a; i++) {
		cout << i << " " << mincost[i] << endl;
	}
}