Go: package main

import (
	"bufio"
	"fmt"
	"os"
)

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

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

		out[u] = q[u]
		delete(q, u)
		visited[u] = struct{}{}
	}

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

func top(q map[int]int) int {
	minu := -1
	min := -1
	for u, d := range q {
		if min < 0 || d < min {
			minu = u
			min = d
		}
	}

	return minu
}

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

using namespace std;

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

    vector<vector<pair<int32_t, int32_t>>> A(n);

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

        for (int32_t j = 0; j < k; j++) {
            int32_t v, c;
            cin >> v >> c;
            A[u].push_back(make_pair(c, v));
        }
    }

    vector<int32_t> d(n, INT32_MAX);
    vector<bool> visited(n, false);
    priority_queue<pair<int32_t, int32_t>, vector<pair<int32_t, int32_t>>, greater<pair<int32_t, int32_t>>> q;
    q.push(make_pair(0, 0));

    while (!q.empty()) {
        int32_t u, d_u;
        tie(d_u, u) = q.top();
        q.pop();

        if (visited[u]) continue;
        visited[u] = true;

        d[u] = d_u;

        for (auto e : A[u]) {
            int32_t v, d_uv;
            tie(d_uv, v) = e;

            if (d[v] > d_u + d_uv) {
                q.push(make_pair(d_u + d_uv, v));
            }
        }
    }

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

    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxx=1010;
const int infinity=1<<30;
int A[maxx][maxx],d[maxx];
bool flag[maxx];
int n,a,b,c;
	
int main (){
	cin>>n;
	for(int i=0;i<n;i++){
		flag[i]=false;
		d[i]=infinity;
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			A[i][j]=infinity;
		}
	}
	for(int i=0;i<n;i++){
		cin>>a>>b;
		for(int j=0;j<b;j++){
			cin>>c>>A[a][c];
		}
	}
	d[0]=0;
	while(1){
		int minv=infinity,minj=-1;
		for(int i=0;i<n;i++){
			if(flag[i]==false && d[i]<minv){
				minv=d[i];
				minj=i;
			}
		}
		if(minv==infinity) break;
		flag[minj]=true;
		for(int i =0;i<n;i++){
			if(A[minj][i]!=infinity && flag[i]==false && d[i]>=d[minj]+A[minj][i]){
					d[i]=d[minj]+A[minj][i];
			}
		}
	}
	for(int i=0;i<n;i++) cout<<i<<" "<<(d[i]==infinity ? -1 : d[i])<<endl;
	
	return 0;

}

C++: #include<stdio.h>
#include<stdlib.h>
#include<limits.h>
struct node {
        int id;
        int weight;
        struct node *next;
};
struct node **list;
int *dist, *prev, *heap, *heap_index, heapsize;
void Insert(int, int, int);
void downheap(int);
void upheap(int);
void PQ_Init(int);
void DijkstraPQ(int, int);
main()
{
        int i, j, n, u, k, v, c;
        scanf("%d", &n);
        list = (struct node**)malloc(sizeof(struct node*) * n);
        for (i = 0; i < n; i++) {
                dist = (int*)malloc(sizeof(int) * n);
                prev = (int*)malloc(sizeof(int) * n);
                list[i] = NULL;
        }
        for (i = 0; i < n; i++) {
                scanf("%d%d", &u, &k);
                for (j = 0; j < k; j++) {
                        scanf("%d%d", &v, &c);
                        Insert(u, v, c);
                }
        }
        DijkstraPQ(0, n);
        for (i = 0; i < n; i++) {
                struct node *p, *q;
                printf("%d %d\n", i, dist[i]);
                for (q = list[i], p = q->next; p != NULL; q = p, p = p->next) {
                        q->next = p->next;
                        free(p);
                }
                if (list[i] != NULL) {
                        free(list[i]);
                }
        }
        free(list);
        free(dist);
        free(prev);
        free(heap);
        free(heap_index);
}
void Insert(int a, int b, int weight)
{
        struct node *p = (struct node*)malloc(sizeof(struct node));
        p->id = b;
        p->weight = weight;
        p->next = list[a];
        list[a] = p;
        p = (struct node*)malloc(sizeof(struct node));
    p->id = a;
    p->weight = weight;
        p->next = list[b];
    list[b] = p;
}
void downheap(int k)
{
        int j, v = heap[k];
        while (k < heapsize / 2) {
                j = 2 * k + 1;
                if (j < heapsize - 1 && dist[heap[j]] > dist[heap[j + 1]]) j++;
                if (dist[v] <= dist[heap[j]]) break;
                heap[k] = heap[j];
                heap_index[heap[j]] = k;
                k = j;
        }
        heap[k] = v;
        heap_index[v] = k;
}
void upheap(int j)
{
        int k, v = heap[j];
        while (j > 0) {
                k = (j + 1) / 2 - 1;
                if (dist[v] >= dist[heap[k]]) break;
                heap[j] = heap[k];
                heap_index[heap[k]] = j;
                j = k;
        }
        heap[j] = v;
        heap_index[v] = j;
}
void PQ_Init(int size)
{
        int i;
        heapsize = size;
        heap = (int*)malloc(sizeof(int) * size);
        heap_index = (int*)malloc(sizeof(int) * size);
        for (i = 0; i < size; i++) {
                heap[i] = i;
                heap_index[i] = i;
        }
        for (i = size / 2 - 1; i >= 0; i--) {
                downheap(i);
        }
}
void DijkstraPQ(int p, int size)
{
        int i;
        for (i = 0; i < size; i++) {
                dist[i] = INT_MAX;
                prev[i] = -1;
        }
        dist[p] = 0;
        PQ_Init(size);
        while (heapsize > 0) {
                struct node *n;
                int u = heap[0];
                heap[0] = heap[heapsize - 1];
                heap_index[heap[size - 1]] = 0;
                heapsize--;
                downheap(0);
                for (n = list[u]; n != NULL; n = n->next) {
                        int w = n->weight, newlen = dist[u] + w;
                        if (newlen < dist[n->id]) {
                                dist[n->id] = newlen;
                                prev[n->id] = u;
                                upheap(heap_index[n->id]);
                        }
                }
        }
}