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>
#define INF 200001
int main(){
  int u,k,C,V,A[1000][1000],D[1000][1000],n;
  std::cin >> n;
  for(int i=0;i<n;i++)for(int j=0;j<n;j++)D[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;
      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]= std::min(D[i][j],D[i][k] + D[k][j]);
  for(int i=0;i<n;i++)std::cout << i << " " << D[0][i] << std::endl;
  return 0;
}

C++: //include
//------------------------------------------
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <limits>
using namespace std;

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>(b);i--)
#define REP(i,n)  FOR(i,0,n)

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//debug
//-------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define INF (1<<21)
#define NOT_VISITED 0
#define FOUND 1
#define VISITED 2

//typedef
//-------------------------------------------
typedef long long ll;
typedef pair<int, int> Pair;

int n;
vector<Pair> g[101];
int d[101];
int p[101];
int visited[101];

int dijkstra(int start) {
    d[start] = 0;
    p[start] = -1;

    while(1) {
        int mincost = INF;
        int u = -1;
        REP(i, n) {
           if (visited[i] != VISITED && d[i] < mincost) {
                mincost = d[i];
                u = i;
            }
        }
        if (u == -1) break;
        visited[u] = VISITED;

        REP(j, n) {
            REP(k, g[u].size()) {
                if (visited[j] != VISITED && g[u][k].first == j) {
                    if (d[u] + g[u][k].second < d[j]) {
                        d[j] = d[u] + g[u][k].second;
                        p[j] = u;
                        visited[j] = FOUND;
                    }
                }
            }
        }
    }
    return 1;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    REP(i, 101) {
        visited[i] = NOT_VISITED;
        d[i] = INF; 
        p[i] = -1;
    }

    cin >> n;
    REP(i, n) {
        int u, k;
        cin >> u >> k;
        REP(j, k) {
            int v, c;
            cin >> v >> c;
            Pair e(v, c);
            g[u].push_back(e);
        }
    }

    dijkstra(0);

    REP(i, n)  {
        cout << i << " " << d[i] << endl;
    }

    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

const int INF=1e9;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N; cin>>N;
    vector<vector<int>> dist(N,vector<int>(N,INF));
    for(int i=0;i<N;i++) dist[i][i]=0;
    for(int i=0;i<N;i++){
        int u,k; cin>>u>>k;
        while(k--){
            int v,c; cin>>v>>c;
            chmin(dist[u][v],c);
        }
    }
    for(int k=0;k<N;k++) for(int i=0;i<N;i++) for(int j=0;j<N;j++){
        chmin(dist[i][j],dist[i][k]+dist[k][j]);
    }
    for(int i=0;i<N;i++){
        cout<<i<<' '<<dist[0][i]<<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
static const int INFTY=(1<<21);
#define WHITE 0
#define GRAY 1
#define BLACK 2
int n,M[102][102],color[102],d[102];
vector <int> searched;
void search(){
    int minp=0,min;
    while(1){
        min=INFTY;
        for(int i=0;i<n;i++){
            if(M[minp][i]!=INFTY&&color[i]==WHITE) color[i]=GRAY;
        }
        for(int i=0;i<searched.size();i++){
            int a=searched[i];
            for(int j=0;j<n;j++){
                if(color[j]==GRAY&&M[a][j]+d[a]<min){
                    min=M[a][j]+d[a];
                    minp=j;
                }
            }
        }
        if(min==INFTY) break;
        else{
            d[minp]=min;
            color[minp]=BLACK;
            searched.push_back(minp);
        }
    }
    for(int i=0;i<n;i++) cout<<i<<" "<<d[i]<<endl;
}
int main(){
    int u,k,v,c;
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++) M[i][j]=INFTY;
    }
    for(int i=0;i<n;i++){
        color[i]=WHITE;
        d[i]=INFTY;
        cin>>u>>k;
        for(int p=0;p<k;p++){
            cin>>v>>c;
            M[u][v]=c;
        }
    }
    searched.push_back(0);
    color[0]=BLACK;
    d[0]=0;
    search();
    return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
using namespace std;

int main(){
	
	int n,aaa;
	cin>>n;
	vector<vector<int>> v(n),c(n);
	vector<int> k(n),ans(n);
	rep(i,n){
		cin>>aaa>>k[i];
		v[i].resize(k[i]);
		c[i].resize(k[i]);
		rep(j,k[i]){
			cin>>v[i][j]>>c[i][j];
		}
		ans[i]=-1;
	}
	ans[0]=0;
	int m=INF,mi,mj;
	rep(aaaa,n-1){
		m=INF;
		rep(i,n){
			if(ans[i]!=-1){
				rep(j,k[i]){
					if(ans[v[i][j]]==-1 && m>ans[i]+c[i][j]){
						m=ans[i]+c[i][j];
						mi=i;
						mj=j;
					}
				}
			}
		}
		ans[v[mi][mj]]=m;
	}
	rep(i,n){
		cout<<i<<" "<<ans[i]<<endl;
	}
	
}