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 <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;
}