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++: #define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
#include <climits>
#include <list>
#include <queue>

using namespace std;

static const int INFTY = -1;

int H;
int A[101];
int NodeNum[101];
int IndexInA[100];


int parent(int i) {
	return i / 2;
}

int left(int i) {
	return 2 * i;
}

int right(int i) {
	return 2 * i + 1;
}

void minHeapify(int i) {
	int l = left(i);
	int r = right(i);
	int smallest = i;
	if (l <= H && A[l] < A[i]) {
		smallest = l;
	}
	if (r <= H && A[r] < A[smallest]) {
		smallest = r;
	}
	if (smallest != i) {
		int temp = A[i];
		A[i] = A[smallest];
		A[smallest] = temp;
		temp = NodeNum[i];
		NodeNum[i] = NodeNum[smallest];
		NodeNum[smallest] = temp;
		IndexInA[NodeNum[i]] = i;
		IndexInA[NodeNum[smallest]] = smallest;

		minHeapify(smallest);
	}
}

void insert(int d, int nodeNum) {
	int i = ++H;
	A[i] = d;
	NodeNum[i] = nodeNum;
	IndexInA[nodeNum] = i;
	int p = parent(i);
	while (i > 1 && A[p] > A[i]) {
		int temp = A[p];
		A[p] = A[i];
		A[i] = temp;
		temp = NodeNum[p];
		NodeNum[p] = NodeNum[i];
		NodeNum[i] = temp;
		IndexInA[NodeNum[p]] = p;
		IndexInA[NodeNum[i]] = i;
		i = p;
		p = parent(i);
	}
}

int heapExtractMinNodeNum() {
	int minNodeNum = NodeNum[1];
	A[1] = A[H];
	NodeNum[1] = NodeNum[H];
	IndexInA[NodeNum[1]] = 1;
	H--;
	minHeapify(1);

	return minNodeNum;
}

void decrese(int i, int value) {
	A[i] = value;
	int p = parent(i);
	while (i > 1 && A[p] > A[i]) {
		int temp = A[p];
		A[p] = A[i];
		A[i] = temp;
		temp = NodeNum[p];
		NodeNum[p] = NodeNum[i];
		NodeNum[i] = temp;
		IndexInA[NodeNum[p]] = p;
		IndexInA[NodeNum[i]] = i;
		i = p;
		p = parent(i);
	}
}

int main() {
	int Dist[100];
	int AdjacenceyList[100][100];
	int AdjacenceyWeightList[100][100];
	int Degree[100];
	int i, j;
	int N;
	int W;
	//int Deg;
	int MinTotalWeight = 0;
	int u, v;
	int k;
	bool inT[100];

	cin >> N;

	//for (i = 0; i < N; i++) {
	//	inT[i] = false;
	//	Dist[i] = INFTY;
	//	Deg = -1;
	//	for (j = 0; j < N; j++) {
	//		cin >> W;
	//		if (W != -1) {
	//			AdjacenceyList[i][++Deg] = j;
	//			AdjacenceyWeightList[i][Deg] = W;
	//		}
	//	}
	//	Degree[i] = Deg + 1;
	//}

	for (i = 0; i < N; i++) {
		inT[i] = false;
		Dist[i] = INFTY;
		cin >> u >> k;
		Degree[u] = k;
		for (j = 0; j < k; j++) {
			cin >> AdjacenceyList[u][j] >> AdjacenceyWeightList[u][j];
		}
	}


	H = 0;
	u = 0;
	inT[u] = true;
	Dist[u] = 0;
	for (i = 1; i <= N - 1; i++) {
		for (j = 0; j < Degree[u]; j++) {
			v = AdjacenceyList[u][j];
			if (inT[v] == false) {
				W = AdjacenceyWeightList[u][j];
				if (Dist[v] == INFTY) {
					//Dist[v] = W;
					//insert(W, v);
					Dist[v] = Dist[u] + W;
					insert(Dist[v], v);
				}
				//else if (W < Dist[v]) {
				else if(W + Dist[u] < Dist[v]){
					//Dist[v] = W;
					//decrese(IndexInA[v], W);
					Dist[v] = W + Dist[u];
					decrese(IndexInA[v], Dist[v]);
				}
			}
		}

		int minNodeNum = heapExtractMinNodeNum();
		inT[minNodeNum] = true;
		//MinTotalWeight += Dist[minNodeNum];
		u = minNodeNum;

	}

	//printf("%d\n", MinTotalWeight);

	for (i = 0; i < N; i++) {
		printf("%d %d\n", i, Dist[i]);
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
vector<int> color;//0:白1:灰2:黒
vector<vector<int>> M;
vector<int> d;
vector<int> p;
typedef long long int Int;

const int INF = 10000000;
int n;
void dijkstra(int s){
    
    for(int i=0;i<n;i++){
        d[i] = INF;
    }
    d[s] = 0;
    p[s] = -1;

    while(1){
        int u=-1;
        int mincost = INF;
        for(int i=0;i<n;i++){
            if(color[i]!=2&&d[i]<mincost){
                mincost = d[i];
                u = i;
            }
        }
        if(mincost == INF) break;
        color[u] = 2;
        for(int v=0;v<n;v++){
            if(color[v]!=2&&M[u][v]!=INF){
                if(d[u]+M[u][v]<d[v]){
                    d[v] = d[u]+M[u][v];
                    p[v] = u;
                    color[v] = 1;
                }
            }
        }
    }
}

int main(){
    cin >> n;
    color.assign(n,0);//0:白1:灰2:黒
    M.assign(n,vector<int>(n,INF));
    d.resize(n);
    p.resize(n);
    for(int i=0;i<n;i++){
        int id,k;cin >> id >> k;
        for(int j=0;j<k;j++){
            int v,cost;cin >> v >> cost;
            M[id][v] = cost;
        }
    }
    dijkstra(0);
    for(int i=0;i<n;i++){
        cout << i << " ";
        cout << d[i] << endl;
    }
}