Go: package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)

	g := makeGraph(n)
	for i := 0; i < n; i++ {
		u := getNextInt(scanner)
		k := getNextInt(scanner)
		for ii := 0; ii < k; ii++ {
			v := getNextInt(scanner)
			c := getNextInt(scanner)
			g[u][v] = c
		}
	}

	ans := make([]int, n)
	im := make(IntMap, 1)
	im.increment(0)
	for len(im) < n {
		min := 1 << 30
		x := -1
		for u := range im {
			for v := 0; v < n; v++ {
				if im.get(v) != 0 {
					continue
				}
				if min > ans[u]+g[u][v] {
					min = ans[u] + g[u][v]
					x = v
				}
			}
		}
		im.increment(x)
		ans[x] = min
	}

	for i := 0; i < n; i++ {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d", i, ans[i]))
	}
	writer.Flush()
}

func makeGraph(n int) [][]int {
	g := make([][]int, n)
	for i := 0; i < n; i++ {
		g[i] = make([]int, n)
		for ii := 0; ii < n; ii++ {
			g[i][ii] = 1 << 30
		}
	}

	return g
}

// IntMap ...
type IntMap map[int]int

func (m IntMap) get(key int) int {
	if _, ok := m[key]; ok {
		return m[key]
	}
	return 0
}
func (m IntMap) increment(key int) {
	if _, ok := m[key]; ok == false {
		m[key] = 0
	}
	m[key]++
}

Python: # coding: utf-8
import queue
nodelist={}
n=int(input())
dist={}
used={}
for i in range(n):
    line=list(map(int,input().split()))
    nodelist[line[0]]=[]
    dist[line[0]]=99999999
    used[line[0]]=False
    j=2
    while True:
        try:
            nodelist[line[0]].append((line[j],line[j+1]))
            j+=2
        except:
            break
q=queue.PriorityQueue()
dist[0]=0
for node in nodelist.keys():
    q.put((dist[node],node))

while not q.empty():
    node=q.get()
    if used[node[1]]:
        continue
    else:
        used[node[1]]=True
    for edge in nodelist[node[1]]:
        if dist[edge[0]]>dist[node[1]]+edge[1]:
            dist[edge[0]]=dist[node[1]]+edge[1]
            q.put((dist[edge[0]],edge[0]))

for d in dist.items():
    print(*d)

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;

}