Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

const T = 10000000

var n int
var A [101][101]int

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func Shortestsearch() {
	var Minimum int
	var d, color [100]int
	var u int

	for i := 0; i < n; i++ {
		d[i] = T
		color[i] = 0
	}

	d[0] = 0
	color[0] = 1

	for {
		Minimum = T
		u = -1
		for i := 0; i < n; i++ {
			if Minimum > d[i] && color[i] != 2 {
				u = i
				Minimum = d[i]
			}
		}
		if u == -1 {
			break
		}
		color[u] = 2
		for j := 0; j < n; j++ {
			if color[j] != 2 && A[u][j] != T {
				if d[j] > d[u]+A[u][j] {
					d[j] = d[u] + A[u][j]
					color[j] = 1
				}
			}
		}
	}
	for i := 0; i < n; i++ {
		fmt.Printf("%d %d\n", i, d[i])
	}
}
func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			A[i][j] = T
		}
	}
	for i := 0; i < n; i++ {
		u := nextInt()
		k := nextInt()
		for j := 0; j < k; j++ {
			v := nextInt()
			c := nextInt()
			A[u][v] = c
		}
	}
	Shortestsearch()
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <climits>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repR(i, n) for(int i = (n) - 1; i > -1; i--)
#define rep1(i, n) for(int i = 1; i < (int)(n + 1); i++)
#define rep1R(i, n) for(int i = (n); i > 0; i--)
using namespace std;
static const int INF = INT_MAX;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

static const int N = 2010;
int M[N][N];
int color[N];
int d[N];
int p[N];
int n;

void dijkstra(int s) {
  rep(u, n) {
    color[u] = WHITE;
    d[u] = INF;
  }
  d[s] = 0;
  p[s] = -1;

  while (true) {
    int mincost = INF;
    int u;
    rep(i, n) {
      if (color[i] != BLACK && d[i] < mincost) {
        mincost = d[i];
        u = i;
      }
    }

    if (mincost == INF) break;

    color[u] = BLACK;

    rep(v, n) {
      if (color[v] != BLACK && M[u][v] != INF) {
        if (d[u] + M[u][v] < d[v]) {
          d[v] = d[u] + M[u][v];
          p[v] = u;
          color[v] = GRAY;
        }
      }
    }
  }
}

int main() {
  cin >> n;
  rep(y, n) rep(x, n) {
    int a;
    cin >> a;
    if (a != -1) M[y][x] = a;
    else M[y][x] = INF;
  }
  dijkstra(0);
  rep(v, n) cout << v << " " << d[v] << endl;
  return 0;
}

C++: #include <iostream>
using namespace std;

const int Max = 100;
const int Infty = (1 << 21);
const int white = 0;
const int gray = 1;
const int black = 2;

int n, M[Max][Max];
int d[Max], p[Max], color[Max];


void dijkstra(int s){
    for(int i=0; i<n; i++){
        d[i] = Infty;
        p[i] = -1;
        color[i] = white;
    }
    d[s] = 0;
    int minv, u;
    while(1){
        minv = Infty;
        u = -1;
        for(int i=0; i<n; i++){
            if(color[i] != black && d[i] < minv){
                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];
                    p[v] = u;
                    color[v] = gray;
                }
            }
        }
    }
    return;
}


int main(){
    cin >> n;
    int u, k, v, c;
    for(int i=0; i<n; i++){
        for(int l=0; l<n; l++){
            M[i][l] = Infty;
        }
        cin >> u >> k;
        for(int j=0; j<k; j++){
            cin >> v >> c;
            M[u][v] = c;
        }
    }

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

    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#define INF 20000 
using namespace std;
int n;
int A[1000][1000];
int d[1000];
bool used[1000];
int D[1000][1000];
 
void Init(int f){
  for(int i=0;i<f;i++){
    for(int j=0;j<f;j++)D[i][j] = INF;
  }
 
}
 
int main(){
  scanf("%d",&n);
  int u,k,C,V;
  Init(n);
  
  for(int i=0;i<n;i++){
      scanf("%d %d",&u,&k);    
      for(int j=0;j<k;j++){
    scanf("%d %d",&V,&C);
    D[u][V] = C;
    D[V][u] = C;
      }    
  }
   
  for(int i=0;i<n;i++)D[i][i] = 0;
  for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++)D[i][j] = min(D[i][j],D[i][k] + D[k][j]);
  for(int i=0;i<n;i++){
    printf("%d %d\n",i,D[0][i]);
  }
 
  return 0;
}

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

const static int MAX = 100;
const static int INF = 1001001001;
int A[MAX][MAX];
int d[MAX];
int p[MAX];
int color[MAX];

int main(void){
    int n, u, k, v, c, mincost, sum;
    std::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++){
	std::cin >> u >> k;
	for(int j = 0; j < k; j++){
	    std::cin >> v >> c;
	    A[u][v] = c;
	}
    }

    d[0] = 0;
    for(int i = 1; i < n; i++){
	d[i] = INF;
    }
    p[0] = -1;
    for(int i = 0; i < n; i++){
	color[i] = 0;
    }

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

	if(mincost == INF) break;

	for(int i = 0; i < n; i++){
	    if(d[i] > d[u] + A[u][i] && color[i] == 0){
		d[i] = d[u] + A[u][i];
		p[i] = u;
	    }
	}
    }

    sum = 0;
    for(int i = 0; i < n; i++){
	color[i] = 0;
    }
    for(int i = 0; i < n; i++){
	int cur = i;
	while(p[cur] != -1 && color[cur] == 0){
	    sum += A[p[cur]][cur];
	    color[cur] = 1;
	    cur = p[cur];
	}
    }
    for(int i = 0; i < n; i++){
	std::cout << i << " " << d[i] << std::endl;
    }



    return 0;
}

C++: #include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#include <climits>
#define int long long
using namespace std;
typedef pair <int,int> P;
#define to first
#define co second
#define fi first
#define se second
const int INF=INT_MAX;
const int MAX_V=100000;
vector <P> G[MAX_V];
int v,d[MAX_V];
void dijk(int s){
  priority_queue <P,vector<P>,greater<P> > que;
  fill(d,d+v,INF);
  d[s]=0;
  que.push(P(0,s));
  for(;!que.empty();){
    P p=que.top(); que.pop();
    int v=p.se;
    if (d[v]<p.fi) continue;
    for(int i=0;i<(int)G[v].size();i++){
      P e=G[v][i];
      if(d[e.to]>d[v]+e.co){
	d[e.to]=d[v]+e.co;
	que.push(P(d[e.to],e.to));
      }
    }
  }
}
signed main(){

  cin>>v;
  for(int i=0,u,k;i<v&&cin>>u>>k;i++) for(int j=0,a,b;j<k&&cin>>a>>b;j++) G[u].push_back(P(a,b));
  dijk(0);
  for(int i=0;i<v;i++) cout<<i<<" "<<d[i]<<endl;
  return 0;

}