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 <queue>
#include <utility>
using namespace std;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;
vector<pair<int, int>> adj[100];
int *d;

void dijkstra() {
    priority_queue<pair<int, int>> PQ;
    int d[n], color[n];

    for (int i = 0; i < n; i++) {
        d[i] = INFTY;
        color[n] = WHITE;
    }
    d[0] = 0;
    PQ.push(make_pair(0, 0));

    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[u] + adj[u][j].second < d[v]) {
                d[v] = d[u] + adj[u][j].second;
                // printf("d[%d] = %d\n", v, d[v]);
                PQ.push(make_pair(d[v] * (-1), v));
                color[v] = GRAY;
            }
        }
    }
    
    for (int i = 0; i < n; i++) {
        printf("%d %d\n", i, d[i]);
    }
}

int main() {
    cin >> 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;
            adj[u].push_back(make_pair(v, c));
        }
    }

    dijkstra();

    return 0;
}

C++: #include <bits/stdc++.h>
#define INF 1e9
using namespace std;
int n,mp[101][101],D[101];

void dijkstra(){
  bool used[101]={};
  for(int i=0;i<101;i++)D[i]=INF;
  D[0]=0;

  while(1){
    int cost=INF,pos=-1;
    for(int i=0;i<n;i++) if(!used[i]&&D[i]<cost) pos=i,cost=D[i];
    if(pos==-1)return ;
    used[pos]=1;    
    for(int i=0;i<n;i++)D[i]=min(D[i],cost+mp[pos][i]);
  }
}


int main(){

  cin>>n;
  for(int i=0;i<101;i++)
    for(int j=0;j<101;j++) mp[i][j]=INF;
  
  for(int i=0,a,m;i<n;i++){
    cin>>a>>m;
    for(int j=0,b,c;j<m;j++)cin>>b>>c,mp[a][b]=c;
  }
  dijkstra();
  for(int i=0;i<n;i++)cout <<i<<" "<<D[i]<<endl;
  
  return 0;
}

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

using namespace std;
using ll =long long;

static const int inf = (1<<21);
static const int white = 0;
static const int gray =  1;
static const int black = 2;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//Write From this Line

int n, M[110][110];

void dijkstra(){ 
	int minv;
	int d[110], color[110];

	for (int i = 0; i < n; i++) {
		d[i] = inf;
		color[i] = white;
	}

	d[0] = 0;
	color[0] = gray;
	while(1) {
		minv = inf;
		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] != inf){
				chmin(d[v],d[u]+M[u][v]);
				color[v] = gray;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		cout << i << " " << (d[i] ==inf ? -1 : d[i]) << endl;
	}
}

int main()
{
	cin >> n;
	rep(i,110){
		rep(j,110){
			M[i][j] = inf;
		}
	}
	rep(i,n){
		int u, k;
		cin >> u >> k;
		rep(j,k){
			int a, b;
			cin >> a >> b;
			M[u][a] = b;
		}
	}
	dijkstra();
	return 0;
}

C++: #include<iostream>
#include<queue>
using namespace std;
#define MAX_N 100
#define MAX_M 100000
int n, c, v;
int dis[MAX_N + 1];
int Adjacency_matrix[MAX_N + 1][MAX_N + 1];
const int INF = 100000000;
void Dijkstra(int s, int g){
  queue<int> que;
  for(int i = 0; i <= MAX_N; i++){
    dis[i] = INF;
  }
  que.push(s);
  dis[s] = 0;
  while(que.size()){
    int p = que.front();
    que.pop();
    for( int i = 0; i < n; i++ ){
      if(Adjacency_matrix[p][i] + dis[p] < dis[i] ){
        que.push(i);
        dis[i] = Adjacency_matrix[p][i] + dis[p];
      }
    }
  }
}

int main(){
  int k_1, u;
  for(int i = 0; i <= MAX_N; i++){
    for( int k = 0; k <= MAX_N; k++){
      Adjacency_matrix[i][k] = INF;
    }
  }
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> u >> k_1;
    for(int j = 1; j <= k_1; j++){
      cin >> v >> c;
      Adjacency_matrix[i][v] = c;
    }
  }
  for(int i = 0; i < n; i++){
    Dijkstra(0, i);
    cout<<i<<" "<<dis[i]<<endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF 9223372036854775807

#define N 100

int G[N][N];
int d[N];

void dijkstra(int s, int n)
{
    int visited[n], p[n];
    for (int i = 0; i < n; i++)
    {
        visited[i] = 0;
        d[i] = INF;
    }
    d[s] = 0;

    while (true)
    {
        int mincost = INF;
        int u = -1;
        for (int i = 0; i < n; i++)
        {
            if (!visited[i] && d[i] < mincost)
            {
                mincost = d[i];
                u = i;
            }
        }

        if (u == -1)
            break;

        visited[u] = 1;
        for (int i = 0; i < n; i++)
        {
            if (G[u][i] != INF && !visited[i])
            {
                if (d[u] + G[u][i] < d[i])
                {
                    d[i] = d[u] + G[u][i];
                    p[i] = u;
                }
            }
        }
    }
}

signed main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            G[i][j] = 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] = c;
        }
    }

    dijkstra(0, n);

    for (int i = 0; i < n; i++)
        cout << i << ' ' << d[i] << endl;
}

C++: #include<iostream>
#define INF 1<<21
using namespace std;
static const int N = 101;
int n,A[N][N];
void dikstra(void){
    int d[N],p[N],color[N],minv;
    for(int i=0;i<n;i++){
        d[i] = INF;
        p[i] = -1;
        color[i] = 0;
    }
    d[0] = 0;
    while(1){
        int u =-1;
        minv = INF;
        for(int i=0;i<n;i++){
            if(d[i]<minv && color[i]!=1){
                u = i;
                minv = d[i];
            }
        }
        if(u==-1){
            break;
        }
        color[u] = 1;
        for(int v=0;v<n;v++){
            if(d[u]+ A[u][v] < d[v] && color[v]!=1){
                d[v] = d[u] + A[u][v];
                p[v] = u;
            }
        }
    }
    for(int i=0;i<n;i++){
        cout << i << ' ' << d[i] << endl;
    }
}
int main(void){
    int u,adj,v;
    cin >> n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            A[i][j] = INF;
        }
    }
    for(int i=0;i<n;i++){
        cin >> u >> adj;
        for(int j=0;j<adj;j++){
            cin >> v >> A[u][v];
        }
    }
    dikstra();
    return 0;
}