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>
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>
using namespace std;
#define MAX 100
#define INF 1 << 30

int n, A[MAX][MAX], d[MAX];
bool vis[MAX];

void dijkstra(int s){
  for ( int i = 0; i < n; i++){
    d[i] = A[s][i];
    vis[i] = false;
  }
  d[s] = 0;
  vis[s] = true;

  while ( 1 ){
    int minCost = INF;
    for ( int i = 0; i < n; i++){
      if ( !vis[i] && minCost > d[i]){
        minCost = d[i];
        s = i;
      }
    }

    if ( minCost == INF ) break;
    vis[s] = true;

    for ( int i = 0; i < n; i++){
      if ( !vis[i] && d[i] > d[s] + A[s][i]){
        d[i] = d[s] + A[s][i];
      }
    }
  }
}

int main(){
  cin >> n;

  // init
  for ( int i = 0; i < n; i++){
    for ( int j = 0; j < n; j++ ){
      A[i][j] = INF;
    }
  }


  int u, k, v, c;
  for ( int i = 0; i < n; i++){
    cin >> u >> k;
    for ( int j = 0; j < k; j++){
      cin >> v >> c;
      A[u][v] = (c == -1) ? INF : c;
    }
  }

  dijkstra(0);

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

  return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
using namespace std;

typedef vector<int>::iterator vitr;
typedef map<int, int>::iterator mitr;

map<int, int> w[100];
int d[100];

vector<int> a;
vector<int> b;

void findPath(){
    int candiW = INT_MAX;
    vitr candiI;
    for(vitr i=a.begin();i!=a.end();i++){
        for(vitr j=b.begin();j!=b.end();j++){
            mitr k = w[*i].find(*j);
            if(k == w[*i].end())continue;
            if(k->second + d[*i] < candiW){
                candiW = k->second + d[*i];
                candiI = j;
            }
        }
    }
    a.push_back(*candiI);
    d[*candiI] = candiW;
    b.erase(candiI);
}

int main(){
    int i,j,u,k,n,v,c;

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

    d[0] = 0;
    a.push_back(0);
    for(i=1;i<n;i++)b.push_back(i);

    for(i=1;i<n;i++)findPath();

    for(i=0;i<n;i++)printf("%d %d\n",i,d[i]);

    return 0;
}

C++: #include <iostream>
using namespace std;
static const int maxs=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[maxs][maxs];

void dicstra(){
  int minv;
  int d[maxs],color[maxs];
  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;
    }
  }
  dicstra();
  return 0;
}

C++: #include<bits/stdc++.h>
#define N 100
#define INFTY (1<<21)
#define WH 0
#define GR 1
#define BL 2
using namespace std;

vector<int> color(N),d(N),p(N);
vector<vector<int>> M(N,vector<int>(N));
int n;

void dijkstra(){
	for(int i=0;i<n;i++){
		color.at(i) = WH;
		d.at(i) = INFTY;
	}
	d.at(0) = 0;
	color.at(0) = GR;
	
	while(1){
		int mincost = INFTY;
		int u = -1;
		for(int i=0;i<n;i++){
			if(color.at(i) != BL && d.at(i) < mincost){
				mincost = d.at(i);
				u = i;
			}
		}
		if(u == -1) break;
		
		color.at(u) = BL;
		
		for(int v=0;v<n;v++){
			if(color.at(v) != BL && M.at(u).at(v) != INFTY){
				if(d.at(u) + M.at(u).at(v) < d.at(v)){
					d.at(v) = d.at(u) + M.at(u).at(v);
					p.at(v) = u;
					color.at(v) = GR;
				}
			}
		}
	}
	for(int i=0;i<n;i++){
		cout << i << " ";
		if(d.at(i) == INFTY) cout << -1 << endl;
		else cout << d.at(i) << endl;
	}
	
}

int main(){
	cin >> n;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			M.at(i).at(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.at(u).at(v) = c;
		}
	}
	dijkstra();
}

C++: #include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF (1<<21)
#define white 0
#define gray 1
#define black 2

int n;
int W[100][100];
int color[100],d[100],p[100];

void dijkstra(int s) {
  d[s] = 0;

  while(1) {

    int mini = INF,u;
    for(int i = 0;i < n;i++) {
      if(color[i] != black && mini > d[i]) {
        mini = d[i];
        u = i;
      }
    }

    if(mini == INF) break;
    color[u] = black;

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

  }

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


int main() {

  cin >> n;
  for(int i = 0;i < n;i++) {
    for(int j = 0;j < n;j++) {
      W[i][j] = INF;
    }
  }

  for(int i = 0;i < n;i++) {
    int u,k;
    cin >> u >> k;
    color[i] = white;
    d[i] = INF;
    for(int j = 0;j < k;j++) {
      int v,c;
      cin >> v >> c;
      W[u][v] = c;
    }
  }

  dijkstra(0);

}