Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

const T = 10000000

var n int
var A [101][101]int

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func Shortestsearch() {
	var Minimum int
	var d, color [100]int
	var u int

	for i := 0; i < n; i++ {
		d[i] = T
		color[i] = 0
	}

	d[0] = 0
	color[0] = 1

	for {
		Minimum = T
		u = -1
		for i := 0; i < n; i++ {
			if Minimum > d[i] && color[i] != 2 {
				u = i
				Minimum = d[i]
			}
		}
		if u == -1 {
			break
		}
		color[u] = 2
		for j := 0; j < n; j++ {
			if color[j] != 2 && A[u][j] != T {
				if d[j] > d[u]+A[u][j] {
					d[j] = d[u] + A[u][j]
					color[j] = 1
				}
			}
		}
	}
	for i := 0; i < n; i++ {
		fmt.Printf("%d %d\n", i, d[i])
	}
}
func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			A[i][j] = T
		}
	}
	for i := 0; i < n; i++ {
		u := nextInt()
		k := nextInt()
		for j := 0; j < k; j++ {
			v := nextInt()
			c := nextInt()
			A[u][v] = c
		}
	}
	Shortestsearch()
}

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]);
                        }
                }
        }
}