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]++
}

C++: #include<iostream>
#include<vector>
#include<deque>
#include<queue> 
#include<functional>
#include<climits>

//#define INF 2147483647
#define INF INT_MAX

using namespace std;

int n;
priority_queue<pair<int, int>,  deque<pair<int,int>>, greater<pair<int,int>>> q;
vector<vector<int>> c;
vector<int> d;


int input(){
  cin >> n;
  int u = 0, k = 0, v = 0;
  c.resize(n);
  for( int i = 0; i < n; i++ ){
    cin >> u >> k;
    c[u].resize(n, -1);
    for( int j = 0; j < k; j++ ){
      cin >> v;
      cin >> c[u][v];
    }
  }
  d.resize(n, INF);
  return 0;
}

int checkContinue(){
  for( int i = 0; i < n; i++ ){
    if( d[i] == INF ){ return 1; }
  }
  return 0;
}

int run(){
  q.emplace(pair<int,int>(0,0));
  while( checkContinue() ){
    pair<int, int> p = q.top();
    q.pop();
    if( d[p.second] < p.first ){ continue; }
    d[p.second] = p.first;
    for( int i = 0; i < n; i++ ){
      if( c[p.second][i] < 0 ){ continue; }
      q.push(pair<int,int>(p.first+c[p.second][i], i));
      // cout << p.first+c[p.second][i] << "," << i << endl;
    }
  }
  for( int i = 0; i < n; i++ ){
    cout << i << " " << d[i] << endl;
  }
  return 0;
}

int main(){
  input();
  run();
  return 0;
}

C++: #include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)

#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define itn ll
#define int ll
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
///                →,↑,←,↓,↗,↖,↙,↘
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };

typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;

static const int MAX = 100;
static const int White = 0;
static const int Gray = 1;
static const int Black = 2;


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

void dijkstra() {
	rep(i, n) {
		color[i] = White;
		d[i] = INF;
		p[i] = -1;
	}
	d[0] = 0;
	while (true) {
		int u, mincost = INF;
		rep(i, n) {
			if (color[i] != Black and d[i] < mincost) {
				u = i;
				mincost = d[i];
			}
		}
		if (mincost == INF) break;
		color[u]  = Black;
		int v;
		rep(v, n) {
			if (color[v] != Black and 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;
				}
			}
		}
	}
	rep(i, n) {
		cout << i << ' ' << d[i] << '\n';
	}
}

signed main() {
	ios::sync_with_stdio(false);
	int i, j, k;
	cin >> n;
	rep(i, n) {
		rep(j, n) {
			M[i][j] = INF;
		}
	}
	rep(i, n) {
		int u, k;
		cin >> u >> k;
		rep(j, k) {
			int c,v;
			cin >> v >> c;
			M[u][v] = c;
		}
	}
	dijkstra();
	return 0;
}

C++: #include<stdio.h>

#define N 103
#define INF 10000000
#define NIL -1
#define BLACK 1

int G[N][N];

int d[N],pi[N],color[N];
int ci[N];
int v[N];

int num;

void initialize(int);
void dij(int);

int main(){
  int i,j;
  int k,u;
  int start=0;

  scanf("%d",&num);

  for(i=0;i<num;i++){
    for(j=0;j<num;j++){
      G[i][j] = NIL;
    }
  }
  

  for(i=0;i<num;i++){
    scanf("%d%d",&u,&k);
      for(j=0;j<k;j++){
	scanf("%d%d",&v[j],&ci[j]);
	G[u][v[j]] = ci[j]; 
      }
  }

  dij(start);

  /*for(i=0;i<num;i++){
    for(j=0;j<num;j++){
      printf("%d ",G[i][j]);
    }
    printf("\n");
  }
  */

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

}

void initialize(int s){
  int v;
  for(v=0;v<num;v++){
    d[v] = INF;
    pi[v] = NIL;
  }

  d[s] = 0;
}

void dij(int s){
  int mincost;
  int i,v,u;
  
  initialize(s);

  while(1){
    
    mincost = INF;

    for(i=0;i<num;i++){
      
      if(color[i] != BLACK && d[i] < mincost){
	mincost = d[i];
	u = i;

      }
    }

    //printf("u=%d\n", u);
    if(mincost == INF) break;

    color[u] = BLACK;
    
    for(v=0;v<num;v++){
      
      if(G[u][v] == -1) continue;
      if(color[v] != BLACK && d[u] + G[u][v] < d[v]){
	pi[v]= u;
	d[v] = d[u] + G[u][v];
      }
    }
  }
}