Go: package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
type Node struct {
	cost int
	done bool
}

type Edge struct {
	to, cost int
}

const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	nodes := make([]Node, N)
	for i := 0; i < N; i++ {
		nodes[i].cost = INF
	}
	E := make([][]Edge, N)
	for i := 0; i < N; i++ {
		id, k := sc.nextInt(), sc.nextInt()
		for j := 0; j < k; j++ {
			to, cost := sc.nextInt(), sc.nextInt()
			E[id] = append(E[id], Edge{to, cost})
		}
	}
	nodes[0].cost = 0
	for {
		cur := 0
		minCost := INF
		for i := 0; i < N; i++ {
			n := nodes[i]
			if !n.done && n.cost < minCost {
				cur = i
				minCost = n.cost
			}
		}
		if minCost == INF {
			break
		}
		nodes[cur].done = true
		for i := 0; i < len(E[cur]); i++ {
			to, cost := E[cur][i].to, E[cur][i].cost+nodes[cur].cost
			if !nodes[to].done && cost < nodes[to].cost {
				nodes[to].cost = cost
			}
		}
	}

	for i := 0; i < N; i++ {
		fmt.Fprintln(wtr, i, nodes[i].cost)
	}
	wtr.Flush()
}

C++: #define dbg(...) fprintf(stderr,__VA_ARGS__)
#define dpr(x) cerr<<#x<<": "<<x<<endl;
#define dprc(c) do{cerr<<#c<<":";for(auto&_i:(c)){cerr<<" "<<_i;}cerr<<endl;}while(0)
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
int INF = 1e9+7;
#define all(c) (c).begin(), (c).end()
#define tr(i,c) for(auto i=(c).begin();i!=(c).end();i++)
#define rtr(i,c) for(auto i=(c).rbegin();i!=(c).rend();i++)
#define rep(i,b) for(auto i=0;i<(b);i++)
#define pb push_back
#define sz(c) int((c).size())

int main(int argc, char **argv)
{
  int n;
  scanf("%d", &n);

  vector<vector<pii>> G(n, vector<pii>());
  for (int i = 0; i < n; i++) {
    int u, k, v, c;
    scanf("%d %d", &u, &k);
    for (int j = 0; j < k; j++) {
      scanf("%d %d", &v, &c);
      G[u].pb(pii(v, c));
    }
  }

  vi d(n, INF);
  vector<bool> visited(n, false);
  int vc = 0;
  priority_queue<pii, vector<pii>, greater<pii>> q;

  d[0] = 0;
  visited[0] = true;
  vc = 1;
  q.push(pii(0, 0));
  
  while(!q.empty()) {
    pii p = q.top(); q.pop();
    int u = p.second;

    if (d[u] < p.first) continue;

    visited[u] = true;
    for (auto e:G[u]) {
      int v = e.first;
      int c = e.second;
      if (!visited[v] && (d[u] + c < d[v])) {
        d[v] = d[u] + c;
        q.push(pii(d[v], v));
      }
    }
  }

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

  return 0;
}

C++: #include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<list>
#include<stack>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

const int MAX = 100;


enum col
  {
   WHITE = 0,
   GRAY =  1,
   BLACK = 2,
  };

using namespace std;
const int INF = 0x7fffffff;

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

void daikusutora(int s){
  int ii,vv;

  //初期化
  for(ii=0;ii<n;ii++){
    color[ii] = WHITE;
    d[ii] = INF;
    p[ii] = -1;
  }
  
  d[s] = 0;
  p[s] = -1;
  
  int mincost,u;
  while(1){
    mincost = INF;
    u = -1;

    //次に選ぶ頂点の決定
    for(ii=0;ii<n;ii++){
      if(color[ii] != BLACK && d[ii] < mincost){

        mincost = d[ii];
        u = ii;
        //cout << "u:" << u << endl;
      }
    }

    //ループの終了条件
    if(mincost == INF){
      break;
    }

    color[u] = BLACK;
    //cout << "color:" << u << endl;

    //次のパスの選択候補
    for(vv=0;vv<n;vv++){
      //未探索の頂点かつ u -> vv へのパスがある場合
      if(color[vv] != BLACK && M[u][vv] != INF){
        //次に探索する候補
        if(d[u] + M[u][vv] < d[vv]){
          //cout << "vv:" << vv << endl;
          d[vv] = d[u] + M[u][vv];
          //color[vv] = GRAY;
        }
      }
    }
    
  }
  
}

int main(){

  long ii,jj,kk;
  int u,k,v,c;
  vector<int> a;

  cin >> n;

  //初期化
  for(ii=0;ii<n;ii++){
    for(jj=0;jj<n;jj++){
      M[ii][jj] = INF;
    }
  }
  
  for(ii=0;ii<n;ii++){

    cin >> u >> k;
    //cout << "u:" << u << "k:" << k << endl;
    for(jj=0;jj<k;jj++){
      cin >> v >> c;
      M[ii][v] = c;
    }
    
  }

  //for(ii=0;ii<n;ii++){
  //  for(jj=0;jj<n;jj++){
  //    cout << M[ii][jj] << " " ;
  //  }
  //  cout << endl;
  //}

  daikusutora(0);

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

C++: #include<iostream>
#include<cstdio>
#define INF 200001 
using namespace std;
int n;
int A[1000][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;
    
      }    
  }
  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;
}