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 <iostream>
#include <cstdlib>
#include <string>
#include <typeinfo>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
static const int INFTY = (1<<20);
static const int MAX =10000;

int n;
vector<pair<int, int> > adj[MAX];

void dijkstra(){
    priority_queue<pair<int, int> > PQ;
    int d[MAX], color[MAX];
    
    for(int i = 0; i < n; i++){
        d[i] = INFTY;
        color[i] = WHITE;
    }
    d[0] = 0;
    PQ.push(make_pair(0,0));
    color[0] = GRAY;
    while(!PQ.empty() ){
        pair<int, int> f = PQ.top();PQ.pop();
        int u = f.second;
        color[u] = BLACK;
        
        if(d[u] < f.first * (-1))continue;
        
        for(int j = 0; j < adj[u].size(); j++){
            int v = adj[u][j].first;
            if(color[v] == BLACK)continue;
            if(d[v] > d[u] + adj[u][j].second){
                d[v] = d[u] + adj[u][j].second;
                PQ.push(make_pair(d[v] * (-1),v));
                color[v] = GRAY;
            }
        }
    }
    for(int i = 0; i < n; i++)cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
}
int main(){
    int k,c,u,v;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> u >> k;
        for(int j = 0; j < k; j++){
            cin >> v >> c;
            adj[u].push_back(make_pair(v,c));
        }
    }
    dijkstra();
    return 0;
}

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

int n,A[MAX][MAX];

void dijkstra(){
  int color[MAX],mincost,k,p[MAX],d[MAX];

  for(int i=0;i<n;i++){
    color[i]=WHITE;
    d[i]=INF;
  }
  d[0]=0;
  p[0]=-1;
  color[0]=GRAY;

  while(1){
    mincost=INF;
    for(int i=0;i<n;i++){
      if(color[i]!=BLACK && d[i]<mincost){
	mincost=d[i];
	k=i;
      }
    }
    if(mincost==INF) break;
    color[k]=BLACK;

    for(int i=0;i<n;i++){
      if(color[i]!=BLACK && A[k][i]!=INF){
	if(d[k]+A[k][i]<d[i]){
	  d[i]=d[k]+A[k][i];
	  p[i]=k;
	  color[i]=GRAY;
	}
      }
    }
  }
  for(int i=0;i<n;i++){
    cout<<i<<" "<<(d[i]==INF ? -1:d[i])<<endl;
  }
}


int main(){
  int i,j,k,c,u,v;
  cin>>n;
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      A[i][j]=INF;
    }
  }
  for(i=0;i<n;i++){
    cin>>u>>k;
    for(j=0;j<k;j++){
      cin>>v>>c;
      A[u][v]=c;
    }
  }

  dijkstra();
}

C++: #include <bits/stdc++.h>
using namespace std;
static const int M=10000;
static int INF=(1<<20);
int n;
vector<pair<int,int > > a[M];
void dijkstra(){
	priority_queue<pair<int,int> > Q;
	int col[M];
	int d[M];
	for(int i=0;i<n;i++){
		col[i]=0;
		d[i]=INF;
	}
	d[0]=0;col[0]=1;
	Q.push(make_pair(0,0));
	while(!Q.empty()){
		pair<int,int>f=Q.top();Q.pop();
		int u=f.second;col[u]=2;
		if(d[u]<f.first)continue;
		for(int j=0;j<a[u].size();j++){
			int v=a[u][j].first;
			if(col[v]==2)continue;
			if(d[v]>d[u]+a[u][j].second){
				d[u]=d[u]+a[u][j].second;
				Q.push(make_pair(d[v]*(-1),v));
				col[v]=1;
			}
		}
	}
	for(int i=0;i<n;i++)cout<<i<<' '<<(d[i]==INF?-1:d[i])<<endl;
}
int main() {
	int k,u,v,c;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>u>>k;
		for(int j=0;j<k;j++){
			cin>>v>>c;
			a[u].push_back(make_pair(v,c));
		}
	}
	dijkstra();
}

C++: #include<iostream>
#include<algorithm>
#include<queue>
#include<utility>
#include<vector>


using namespace std;



int main() {
	int n,tmp1,tmp2,size;
	int cnt_arrived=0;
	pair<int, int> ptmp;
	priority_queue<pair<int, int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
	cin >> n;
	int** mat = new int* [n];
	vector<pair<int, int>>* list_adjacent = new vector<pair<int, int>>[n];
	int* dist = new int[n];
	for (int i = 0;i < n;i++) {
		cin >> tmp1 >> size;
		for (int j = 0;j < size;j++) {
			cin >> tmp1 >> tmp2;
			list_adjacent[i].push_back(make_pair(tmp1, tmp2));
		}
		dist[i] = -1;
	}
	pq.push(make_pair(0, 0));
	while (cnt_arrived < n) {
		ptmp = pq.top();
		pq.pop();
		if (dist[ptmp.second] == -1) {
			cnt_arrived++;
			dist[ptmp.second] = ptmp.first;
			for (int i = 0;i < list_adjacent[ptmp.second].size();i++) {
				pq.push(make_pair(ptmp.first + list_adjacent[ptmp.second][i].second, list_adjacent[ptmp.second][i].first));
			}
		}
	}
	for (int i = 0;i < n;i++) {
		cout << i << " " << dist[i] << endl;
	}
}

C++: #include<iostream>
#include<limits>
using namespace std;

static const int MAX=100;
static const int INFTY=numeric_limits<int>::max();

typedef enum {
    WHITE,
    GRAY,
    BLACK,
}Color;

int n,M[MAX][MAX];

void Dijkstra(){
    int minv;
    int d[MAX];
    Color color[MAX];

    for(int i=0;i<n;i++){
        d[i]=INFTY;
        color[i]=WHITE;
    }
    
    d[0]=0;
    color[0]=GRAY;
    while(true){
        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;
}