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>

using namespace std;


static const int white = 0;
static const int black = 1;
static const int emp = -1;
static const int inf = 1000000;

int graph[124][124] = {{}};
int d[124] = {};
int n;



void dijkstra(){

  int u,mincost;
  int p[124] = {};
  int color[124] = {};

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

  d[0] = 0;

  while(1){

    mincost = inf;
    for(int i = 0;i < n;i++){
      if(color[i] != black && mincost > d[i]){
	mincost = d[i];
	u = i;
      }
    }
    //  cout << "u =  " << u << endl;

    if(mincost == inf) break;
    color[u] = black;

    for(int i = 0;i < n;i++){
      if(color[i] != black && graph[u][i] != emp){
	if(d[u] + graph[u][i] < d[i]){
	  d[i] = d[u] + graph[u][i];
	  p[i] = u;
	}
      }
    }
  }
}


int main(){

  int u,k,ui,c;
  cin >> n;



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


  for(int i = 0;i < n;i++){

    cin >> u >> k;
    for(int j = 0;j < k;j++){
      cin >> ui >> c;
      graph[u][ui] = c;
    }
  }


  dijkstra();

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

}

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

struct Node {
	int id;
	std::vector<int> edge_to;
	std::vector<int> edge_cost;
	bool done;
	int cost;
};

int min(int x, int y)
{
	return x>y ? y : x;
}

void insert(Node* nodes, std::vector<int>& q, int t)
{
	std::vector<int>::iterator it = q.begin();
	for (; it != q.end(); ++it) {
		if (nodes[*it].id == nodes[t].id) return;
		if (nodes[*it].cost > nodes[t].cost) break;
	}
	q.insert(it, t);
}

int main()
{
	int n; std::cin >> n;
	
	Node* nodes = new Node[n];
	
	for (int i=0; i<n; i++) {
		nodes[i].done = false;
		nodes[i].cost = INT_MAX;
	}
	
	for (int i=0; i<n; i++) {
		int id, deg;
		std::cin >> id >> deg;
		nodes[i].id = id;
		for (int j=0; j<deg; j++) {
			int t, cost;
			std::cin >> t >> cost;
			nodes[i].edge_to.push_back(t);
			nodes[i].edge_cost.push_back(cost);
		}
	}
	
	std::vector<int> que;
	que.push_back(0);
	nodes[0].cost = 0;
	
	while (!que.empty()) {
		int s = que[0]; que.erase(que.begin());
		nodes[s].done = true;
		for (int k=0; k<nodes[s].edge_to.size(); k++) {
			int t = nodes[s].edge_to[k];
			int cost = nodes[s].edge_cost[k];
			if (nodes[t].done) continue;
			nodes[t].cost = min(nodes[t].cost, nodes[s].cost + cost);
			insert(nodes, que, t);
		}
	}
	
	for (int i=0; i<n; i++) {
		std::cout << nodes[i].id << " " << nodes[i].cost << std::endl;
	}
	
	delete[] nodes;
	
	return 0;
}

C++: #include <cstdio>
#include <algorithm>
#include <queue>
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() {
    scanf("%d", &n);

    // adj = new vector<pair<int, int>>[n];

    for (int i = 0; i < n; i++) {
        int u, k;
        scanf("%d %d", &u, &k);
        for (int j = 0; j < k; j++) {
            int v, c;
            scanf("%d %d", &v, &c);
            adj[u].push_back(make_pair(v, c));
        }
    }

    dijkstra();

    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define INF 1<<30
struct edge{int to,cost;};
vector<edge> G[101];
int d[101];
bool visited[101];
void dijkstra(int n){
  fill(d+1,d+101,INF);
  memset(visited,false,sizeof(visited));
  for(int i=0;i<n;++i){
    int id=-1;
    for(int j=0;j<n;++j){
      if(!visited[j]){
        if(id==-1||d[id]>d[j]) id=j;
      }
    }
    visited[id]=true;
    for(int j=0;j<G[id].size();++j){
      edge e=G[id][j];
      d[e.to]=min(d[e.to],d[id]+e.cost);
    }
  }
}
int main(){
  int n; cin>>n;
  for(int i=0;i<n;++i){
    int u,k; cin>>u>>k;
    for(int j=0;j<101;++j) G[i].clear();
    for(int j=0;j<k;++j){
      int c,v; cin>>c>>v;
      edge e; e.to=c, e.cost=v;
      G[u].push_back(e);
    }
    dijkstra(n);
  }
  for(int i=0;i<n;++i) cout<<i<<" "<<d[i]<<endl;
  return 0;
}

C++: #include<iostream>
using namespace std;
#define MAX 100+5
#define white 0
#define black 1
#define INF 100000*100+5
int m[MAX][MAX],color[MAX],d[MAX],num;
void dijkstra(){
	d[0]=0;int now_node;
while(true){
	int minc=INF;
	for(int i=0;i<num;i++){
		if(!color[i]&&d[i]<minc){
			minc=d[i];now_node=i;
		}
	}
     	if(minc==INF) break;
		color[now_node]=black;
		for(int i=0;i<num;i++){
			if(color[i]==white&&m[now_node][i]+d[now_node]<d[i]){
				d[i]=d[now_node]+m[now_node][i];
			}
		}
	
}
return ;
}
int main(){
	cin>>num;
	for(int i=0;i<num;i++){
		for(int j=0;j<num;j++){
			m[i][j]=INF;
		}
	}
	int row,n,col,val;
	for(int i=0;i<num;i++){
		cin>>row;
		cin>>n;
		for(int j=0;j<n;j++){
			cin>>col>>val;
			m[row][col]=val;
		}
	}
	for(int i=0;i<num;i++){
		d[i]=INF;color[i]=0;
	}
	dijkstra();
	for(int i=0;i<num;i++){
		cout<<i<<" "<<d[i]<<endl;
	}
}