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 <string>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int i=(a);i<b;i++)
#define INF 1000000000
#define MAX_N 100000000
#define MAX 
using namespace std;
bool debug=false;

int cost[105][105];
int d[105];
bool used[105];
int n;

void Input(){
  cin>>n;
  rep(i,0,n)rep(j,0,n)cost[i][j]=INF;
  for(int i=0;i<n;i++){
  	int from,to,num,c;
  	cin>>from>>num;
  	for(int j=0;j<num;j++){
  		cin>>to>>c;
  		cost[from][to]=c;
  	}
  }
  rep(i,0,105){
    used[i]=false;
    d[i]=INF;
  }
}

void solve(){
  d[0]=0;
  while(1){
    int vertex=-1;

    for(int i=0;i<n;i++){
      if(!used[i]&&(vertex==-1||d[i]<d[vertex])){
	    vertex=i;
      }
    }
    if(vertex==-1)break;
    used[vertex]=true;
    for(int i=0;i<n;i++){
      d[i]=min(d[i],d[vertex]+cost[vertex][i]);
    }
  }
}

int main(){
  Input();
  cout<<"a"<<endl;
  solve();
  for(int i=0;i<n;i++)cout<<i<<" "<<d[i]<<endl;
  return 0;
}

C++: #include <iostream>
#include <iomanip>


using namespace std;

const int  MAXN = 150;
const int IFNTY = 1 << 20;
const int NIL = -1;


void dijkstra(int adj_matrix[][MAXN], int n, int u, int dis[]);


int main()
{
	int adj_matrix[MAXN][MAXN];
	
	
	
	for (int i = 0; i < MAXN; i++)
	{
		for (int j = 0; j < MAXN; j++)
		{
			adj_matrix[i][j] = IFNTY;			
		}
	}

	int n;
	cin >> n;
	
	for (int i = 1; i <= n; i++)
	{
		int ID1, degree;
		cin >> ID1 >> degree;
		for (int j = 1; j <= degree; j++)
		{
			int ID2, weight;	
			cin >> ID2 >> weight;
			adj_matrix[ID1][ID2] = weight;		
		}
	}	
	
//	for (int i = 0; i < n; i++)
//	{
//		for (int j = 0; j < n; j++)
//		{
//			if (adj_matrix[i][j] == IFNTY)
//				cout << setw(3) << "-" << " ";
//			else
//				cout << setw(3) << adj_matrix[i][j] << " ";			
//		}
//		cout << endl;
//	}

	int dis[MAXN];	
	
	dijkstra(adj_matrix, n, 0, dis);
	
	for (int i = 0; i < n; i++)
	{
		cout << i << ' ' << dis[i] << endl;
	}
}



void dijkstra(int adj_matrix[][MAXN], int n, int u, int dis[])
{
	bool visited[MAXN] = {0};
	
	for (int v = 0; v < n; v++)
	{
		dis[v] = adj_matrix[u][v];
	}
	
	dis[u] = 0;
	visited[u] = true;
	
	while (true)
	{
		int w = NIL;
		int min = IFNTY;
		for (int v = 0; v < n; v++)
		{
			if (min > dis[v] && !visited[v])
			{
				w = v;
				min = dis[v];
			}
		}
		
		
		if (w == NIL) break;
		
		visited[w] = true;
		for (int v = 0; v < n; v++)
		{
			if (dis[v] > dis[w] + adj_matrix[w][v])
			{
				dis[v] = dis[w] + adj_matrix[w][v];
			}
		}
	}
}

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>
#include <limits>

constexpr int MAXN = 100;
int G[MAXN][MAXN];
int P[MAXN];
int D[MAXN];
int C[MAXN];

constexpr int MAXINT = std::numeric_limits<int>::max();

int main() {
    int n;
    std::cin >> n;

    for (int i = 0 ; i < n; i++) {
        for (int j = 0 ; j < n; j++) {
            G[i][j] = MAXINT;
        }
    }

    for (int i = 0; i < n; i++) {
        D[i] = MAXINT;
    }

    for (int i = 0; i < n; i++) {
        int id, e_num;
        std::cin >> id >> e_num;
        for (int j = 0; j < e_num; j++) {
            int t;
            std::cin >> t;
            std::cin >> G[id][t];
        }
    }

    int r = 0;
    D[r] = 0;
    while (true) {
        int mincost = MAXINT;
        int m;
        for (int i = 0; i < n; i++) {
            if ((C[i] == 0) && (D[i] < mincost)) {
                mincost = D[i];
                m = i;
            }
        }

        if (mincost == MAXINT) {
            break;
        }

        C[m] = 1;
        for (int i = 0; i < n; i++) {
            if ((C[i] != 1) && (G[m][i] != MAXINT)&& ((D[m] + G[m][i]) < D[i])) {
                P[i] = m;
                D[i] = D[m] + G[m][i];
            }
        }
    }

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

}

C++: #include <bits/stdc++.h>
using namespace std;
static const int M=10000;
static const 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*(-1))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();
}