Go: package main

import (
	"fmt"
	"container/heap"
)

type Node struct {
	Id int
	Dis int
}

type PriorityQueue []*Node

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].Dis < pq[j].Dis
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *PriorityQueue) Push(x interface{}) {
	*pq = append(*pq, x.(*Node))
}

func (pq *PriorityQueue) Pop() interface{} {
	n := len(*pq)
	pop := (*pq)[n-1]
	*pq = (*pq)[0:n-1]
	return pop
}

func main() {
	var n int
	fmt.Scan(&n)

	g := make([][]int, n)
	c := make([][]int, n)
	pq := make(PriorityQueue, 0, n)
	d := make([]int, n)
	for i := 0; i < n; i++ {
		var u,k int
		fmt.Scan(&u)
		fmt.Scan(&k)
		g[u] = make([]int, k)
		c[u] = make([]int, k)
		for j := 0; j < k; j++ {
			fmt.Scan(&g[u][j])
			fmt.Scan(&c[u][j])
		}

		if u == 0 {
			d[u] = 0
		} else {
			d[u] = 1 << 30
		}
		pq.Push(&Node{u, d[u]})
	}
	heap.Init(&pq)

	for pq.Len() > 0 {
		node := heap.Pop(&pq).(*Node)
		for i := 0; i < len(g[node.Id]); i++ {
			nextId := g[node.Id][i]
			nextDis := node.Dis + c[node.Id][i]
			if nextDis < d[nextId] {
				d[nextId] = nextDis
				heap.Push(&pq, &Node{nextId, nextDis})
			}
		}
	}

	for i := 0; i < n; i++ {
		fmt.Println(i, d[i])
	}
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
const int inf=0x3f3f3f3f;
const int maxn=109;
int map1[maxn][maxn];
int flag[maxn];
int vis[maxn];
int c[maxn];

void spfa(int u,int n){
    queue<int>q;
    memset(flag,0,sizeof(flag));
    memset(c,0,sizeof(c));
    for(int i=0;i<n;i++)
        vis[i]=inf;
    vis[0]=0;c[0]=1,flag[0]=1;
    q.push(0);
    while(!q.empty()){
        int now=q.front();
        q.pop();
        flag[now]=0;
        for(int i=0;i<n;i++){
            if(vis[i]>vis[now]+map1[now][i]){
                vis[i]=vis[now]+map1[now][i];
                if(!flag[i]){
                    flag[i]=1;
                    q.push(i);
                }

            }
        }
    }
}

int main(){
    int n,u,v,w,k;
    while(scanf("%d",&n)!=EOF){
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
                if(i==j)
                    map1[i][j]=0;
                else
                    map1[i][j]=inf;
        for(int i=0;i<n;i++){
            scanf("%d%d",&u,&k);
            for(int j=0;j<k;j++){
                scanf("%d%d",&v,&w);
                if(map1[u][v]>w)
                    map1[u][v]=w;
            }
        }
        spfa(0,n);
        for(int i=0;i<n;i++)
            printf("%d %d\n",i,vis[i]);
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#define INF 1<<30
using namespace std;
int main() {
	cin.tie(0);ios::sync_with_stdio(false);
	int V; cin >> V;
	vector<vector<pair<int, int>>> g(V);
	vector<int> dp(V);
	queue<int> q;

	//input
	for (int i = 0; i < V; i++) {
		int u, k; cin >> u >> k;
		for (int j = 0; j < k; j++) {
			int c, v;
			cin >> c >> v;
			g[u].push_back(make_pair(c, v));
		}
	}

	//initialize
	fill(dp.begin(), dp.end(), INF);
	dp[0] = 0;
	q.push(0);

	//Dijkstra
	while (!q.empty()) {
		int k = q.front(); q.pop();
		for (int i = 0; i < g[k].size();i++) {
			int next = g[k][i].first;
			int w = g[k][i].second;
			if (dp[k] + w < dp[next]) {
				dp[next] = dp[k] + w;
				q.push(next);
			}
		}
	}

	//output
	for (int i = 0; i < V;i++) {
		cout << i << " " << dp[i] << endl;
	}
}

C++: #include <cstdio>
#include <algorithm>
#include <queue>
#include <utility>
#include <unordered_map>
#include <vector>

using edge = std::pair<int, int>;
#define N 100

int main(){
    int n;
    std::scanf("%d", &n);
    std::vector<edge> a[N];
    for(int i = 0; i < n; ++i){
        int id;
        int num;
        std::scanf("%d", &id);
        std::scanf("%d", &num);
        for(int j = 0; j < num; ++j){
            edge e;
            std::scanf("%d", &e.second);//id                                                                                                                                                                                        
            std::scanf("%d", &e.first);//weight                                                                                                                                                                                     
            a[id].push_back(e);
        }
    }
    std::priority_queue<edge, std::vector<edge>, std::greater<edge> > que;
    std::unordered_map<int, int> checked;
    checked.insert(std::make_pair(0, 0));
    for(auto &x: a[0]){
        que.push(x);
    }
    while(checked.size() != n){
        while(checked.find(que.top().second) != checked.end()){
            que.pop();
        }
        edge e = que.top();
        que.pop();
        checked.insert(std::make_pair(e.second, e.first));
        for(auto &x: a[e.second]){
            if(checked.find(x.second) == checked.end()){
                x.first += e.first;
                que.push(x);
            }
        }
    }

    for(int i = 0; i < n; ++i){
        auto x = checked.find(i);
        std::printf("%d %d\n", x->first, x->second);
    }

    return 0;
}

C++: #include<iostream>
using namespace std;
static const int MAX=100;
static const int INFTY=(1<<21);
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;
int n,M[MAX][MAX];
void dijkstra(){
int minv;
int d[MAX],color[MAX];
for(int i=0;i<n;i++){
d[i]=INFTY;
color[i]=WHITE;
}
d[0]=0;
color[0]=GRAY;
while(1){
minv=INFTY;
int u=-1;
for(int i=0;i<n;i++){
if(minv>d[i]&&color[i]!=BLACK){
u=i;
minv=d[i];
}
}
if(u==-1)break;
color[u]=BLACK;
for(int v=0;v<n;v++){
if(color[v]!=BLACK&&M[u][v]!=INFTY){
if(d[v]>d[u]+M[u][v]){
d[v]=d[u]+M[u][v];
color[v]=GRAY;
}
}
}
}
for(int i=0;i<n;i++){
cout<<i<<" "<<(d[i]==INFTY？-1:d[i])<<endl;
}
}
int main(){
cin>>n;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
M[i][j]=INFTY;
}
}
int k,c,u,v;
for(int i=0;i<n;i++){
cin>>u>>k;
for(int j=0;j<k;j++){
cin>>v>>c;
M[u][v]=c;
}
}
dijkstra();
return 0;
}

C++: #include <iostream>
using namespace std;
static const int MAX=100;
static const int INFTY=(1<<21);
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;

int n,M[MAX][MAX];
int prim(){
    int minv;
    int d[MAX],color[MAX];
    for(int i=0;i<n;i++){
        d[i]=INFTY;
        color[i]=WHITE;
    }
    d[0]=0;
    color[0]=GRAY;
    while(1){
        minv=INFTY;
        int u=-1;
        for(int i=0;i<n;i++){
            if(minv>d[i]&&color[i]!=BLACK){
                u=i;
                minv=d[i];
            }
        }
        if(u==-1)break;
        color[u]=BLACK;
        for(int v=0;v<n;v++){
            if(color[v]!=BLACK&&M[u][v]!=INFTY){
             if(d[v]>d[u]+M[u][v]){
                 d[v]=d[u]+M[u][v];
                 color[v]=GRAY;
               }
            }
        }
    }
    for(int i=0;i<n;i++){
        cout<<i<<" "<<(d[i]==INFTY ? -1: d[i])<<endl;
    }
}
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            M[i][j]=INFTY;
        }
    }
    int k,c,u,v;
    for(int i=0;i<n;i++){
        cin>>u>>k;
        for(int j=0;j<k;j++){
            cin>>v>>c;
            M[u][v]=c;
        }
    }
    prim();
    return 0;
}