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

	list := make([][]int, n)
	weight := make([]int, n)
	for i := range list {
		list[i] = make([]int, n)
		weight[i] = NIL
		for j := range list[i] {
			list[i][j] = NIL
		}
	}

	for i := 0; i < n; i++ {
		u := scanInt()
		k := scanInt()
		for j := 0; j < k; j++ {
			v := scanInt()
			w := scanInt()
			list[u][v] = w
		}
	}

	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 i, w := range list[node.id] {
			if w == NIL {
				continue
			}
			heap.Push(h, Node{id: i, weight: w + node.weight})
		}
	}

	w := bufio.NewWriter(os.Stdout)
	for i := 0; i < n; i++ {
		fmt.Fprint(w, i)
		fmt.Fprint(w, " ")
		fmt.Fprint(w, weight[i])
		fmt.Fprintln(w)
	}
	w.Flush()
}

C++: #include<iostream>
using namespace std;
#define MAX 100+5
#define white 0
#define black 1
#define INF 100000*100+5
int m[MAX][MAX],color[MAX],d[MAX],num;
void dijkstra(){
	d[0]=0;int now_node;
while(true){
	int minc=INF;
	for(int i=0;i<num;i++){
		if(!color[i]&&d[i]<minc){
			minc=d[i];now_node=i;
		}
	}
     	if(minc==INF) break;
		color[now_node]=black;
		for(int i=0;i<num;i++){
			if(color[i]==white&&m[now_node][i]+d[now_node]<d[i]){
				d[i]=d[now_node]+m[now_node][i];
			}
		}
	
}
return ;
}
int main(){
	cin>>num;
	for(int i=0;i<num;i++){
		for(int j=0;j<num;j++){
			m[i][j]=INF;
		}
	}
	int row,n,col,val;
	for(int i=0;i<num;i++){
		cin>>row;
		cin>>n;
		for(int j=0;j<n;j++){
			cin>>col>>val;
			m[row][col]=val;
		}
	}
	for(int i=0;i<num;i++){
		d[i]=INF;color[i]=0;
	}
	dijkstra();
	for(int i=0;i<num;i++){
		cout<<i<<" "<<d[i]<<endl;
	}
}

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

using namespace std;
using graph = vector<vector<int>>;


int main() {
    int n;
    cin >> n;

    graph G(n, vector<int>(n, -1));
    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;
            G[u][v] = c;
        }
    }

    // Dijkstra's algorithm
    vector<int> d(n, -1);
    vector<bool> visited(n, false);

    d[0] = 0;
    visited[0] = true;
    while (1) {
        int u = -1;
        int v = -1;
        int minw = numeric_limits<int>::max();
        for (int i = 0; i < n; ++i) {
            if (!visited[i])
                continue;
            for (int j = 0; j < n; ++j) {
                if (visited[j] && G[i][j] < 0)
                    continue;
                int w = G[i][j] + d[i];
                if (w < minw) {
                    u = i;
                    v = j;
                    minw = w;
                }
            }
        }
        if (v < 0) {
            break;
        }
        d[v] = minw;
        visited[v] = true;
    }

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

    return 0;
}