Go: package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

//make priority queue
type Item struct {
	id       int
	priority int // this state is priority and distans from start
	index    int
}

type PriorityQueue []*Item

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

// we want the ascending-priority-queue.
// So we use less than here.
func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].priority < pq[j].priority
}

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

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	item.index = -1 //for safety
	*pq = old[0 : n-1]
	return item
}

func (pq *PriorityQueue) update(dist int, id int) {
	for _, i := range *pq {
		if i.id == id {
			if i.priority > dist {
				i.priority = dist
			}
		}
	}
}

// the main code
func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

func dikstra(dist [][]int, n int) []int {
	// preparate priority queue
	inf := 1 << 30
	pq := make(PriorityQueue, n)
	shortests := make([]int, n)
	for i := 0; i < n; i++ {
		pq[i] = &Item{
			id:       i,
			priority: inf,
			index:    i,
		}

		shortests[i] = inf
	}
	pq[0].priority = 0
	shortests[0] = 0
	heap.Init(&pq)

	for pq.Len() > 0 {
		item := heap.Pop(&pq).(*Item)
		shortests[item.id] = item.priority
		for id, d := range dist[item.id] {
			if d != -1 {
				pq.update(item.priority+d, id)
			}
		}
		heap.Init(&pq)
	}
	return shortests
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	// init
	n := nextInt(sc)
	dist := make([][]int, n)
	for i := 0; i < n; i++ {
		dist[i] = make([]int, n)
		for j := 0; j < n; j++ {
			dist[i][j] = -1
		}
	}

	// std Input
	for i := 0; i < n; i++ {
		u := nextInt(sc)
		k := nextInt(sc)
		for j := 0; j < k; j++ {
			v, c := nextInt(sc), nextInt(sc)
			dist[u][v] = c
		}
	}

	shortests := dikstra(dist, n)
	for i, d := range shortests {
		fmt.Printf("%d %d\n", i, d)
	}
}

C++: #include<iostream>
#include<algorithm>
#define inf 10000000
#define W 0
#define G 1
#define B 2
using namespace std;
int n,color[100];
int g[100][100],d[100],p[100];

void dikstr(int st){
int u,i,j;
	for(i=0;i<n;i++){
	color[i]=W;d[i]=inf;
	}
	d[st]=0;
	p[st]=-1;
	while(true){
	int mincost=inf;
		for(i=0;i<n;i++){
			if(color[i]!=B && d[i]<mincost){
			mincost=d[i];
				u=i;
			}
			
		}
		if(mincost==inf)
		break;
		color[u]=B;
		for(int v=0;v<n;v++){
			if(color[v]!=B && g[u][v]!=inf){
				if(d[u]+g[u][v]<d[v]){
				d[v]=d[u]+g[u][v];
					p[v]=u;
					color[v]=G;
				}
			}
		}
	}
}
main(){
	int i,j,u,k,c,v;
	cin>>n;
	for(i=0;i<n;i++){
		for(j=0;j<n;j++)
		g[i][j]=inf;
	}
	for(i=0;i<n;i++){
	cin>>u>>k;
		for(j=0;j<k;j++){
		cin>>v>>c;
			g[u][v]=c;
		}
	}
	dikstr(0);
	
	for(i=0;i<n;i++)
	cout<<i<<" "<<d[i]<<endl;
	return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
const int INF=1000000000;
int G[100][100];
int d[100],used[100];
int n;
void dijkstra(int s){
    fill(d,d+n,INF);
    fill(used,used+n,false);
    
    d[s]=0;
    while(true){
	int v=-1;
	for(int u=0;u<n;u++){
	    if(used[u]) continue;
	    if(v==-1||d[u]<d[v]) v=u;
	}
	if(v==-1) break;
	used[v]=true;

	for(int u=0;u<n;u++){
	    d[u]=min(d[u],d[v]+G[v][u]);
	}
    }
}
int main(){
    cin>>n;
    fill(G[0],G[n],INF);
    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]=G[v][u]=c;
	}
    }
    dijkstra(0);
    for(int i=0;i<n;i++){
	cout<<i<<" "<<d[i]<<endl;
    }

    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 dik(){
int min;
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){
min=INFTY;
int u=-1;
for(int i=0;i<n;i++){
if(min>d[i]&&color[i]!=BLACK){
u=i;
min=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;
}
}

dik();

return 0;
}

C++: #include <stdio.h>
#include <queue>
using namespace std;
struct side{
    int to;
    int cost;
};
struct walk{
    int now;
    int cost;
};
int main(){
    int n,l,m,d[100];
    queue<walk> q;
    vector<side> map[100];
    walk temp,t;
    side s;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d%d",&l,&m);
        d[i]=-1;
        for(int j=0;j<m;j++){
            scanf("%d%d",&s.to,&s.cost);
            map[l].push_back(s);
        }
    }
    temp.now=temp.cost=0;
    q.push(temp);
    while(!q.empty()){
        temp=q.front();
        q.pop();
        if(d[temp.now]!=-1&&d[temp.now]<=temp.cost)continue;
        d[temp.now]=temp.cost;
        for(int i=0;i<map[temp.now].size();i++){
            t.cost=temp.cost+map[temp.now][i].cost;
            t.now=map[temp.now][i].to;
            q.push(t);
        }
    }
    for(int i=0;i<n;i++){
        printf("%d %d\n",i,d[i]);
    }
}

C++: #include <bits/stdc++.h>

using namespace std;

struct edge {
  int to, weight;
};

void dijkstra(vector<vector<edge>> graph, int start) {
  int n = graph.size();

  int dist[n];
  for (int i = 0; i < n; i++) {
    dist[i] = INT_MAX;
  }
  dist[start] = 0;

  priority_queue<pair<int, int>> que;
  que.push(make_pair(dist[start], start));
  while (!que.empty()) {
    int v = que.top().second;
    int c = que.top().first;
    que.pop();
    for (int i = 0; i < graph[v].size(); i++) {
      edge e = graph[v][i];
      if (dist[e.to] > c + e.weight) {
        dist[e.to] = c + e.weight;
        que.push(make_pair(dist[e.to], e.to));
      }
    }
  }

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

int main() {
  int n;
  cin >> n;
  vector<vector<edge>> graph;
  graph.resize(n);
  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;
      graph[u].emplace_back(edge{v, c});
    }
  }

  dijkstra(graph, 0);
}