Go: package main

import (
	"strconv"
	"fmt"
	"bufio"
	"os"
)
const INF = 1 << 21
var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}


func main() {
	scanner.Split(bufio.ScanWords)
	n := nextInt()
	adj := make([][]int, n)
	for i := range adj {
		adj[i] = make([]int, n)
	}

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

	// for i := range adj {
	// 	fmt.Println(adj[i])
	// }

	dist := make([]int, n)
	prev := make([]int, n)
	visited := make([]bool, n)
	dijkstra := func(start int, size int) {
		for i := 0; i < size; i++ {
			dist[i] = INF
			prev[i] = -1
			visited[i] = false
		}
		dist[start] = 0
		for {
			u := -1
			tmp_min := INF
			for i := 0; i < size; i++ {
				if visited[i] == false && dist[i] < tmp_min {
					tmp_min = dist[i]
					u = i
				}
			}
			if u == -1 {
				break
			}
			visited[u] = true
			for i := 0; i < size; i++ {
				if adj[u][i] > 0 {
					w := adj[u][i]
					newlen := dist[u] + w
					if newlen < dist[i] {
						dist[i] = newlen
						prev[i] = u
					}
				}
			}
		}
	}
	dijkstra(0, n)
	for i, cost := range dist {
		fmt.Printf("%d %d\n", i, cost)
	}
}

C++: #include<iostream>
#include<cstdio>
#define INF 200001 
using namespace std;
  
int main(){
 int u,k,C,V,A[1000][1000],D[1000][1000],n;
  scanf("%d",&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++){
      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;
}

C++: #include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#define FOR(i, a, b)  for(int i=a;i<=b;++i)
#define rep(i, n) for(int i=0;i<n;++i)
using namespace std;
struct TRAVEL{
  int to;
  int cost;
};
int main(){
  int n;  cin >> n;
  vector<TRAVEL> g[n];
  int d[n];
  bool flag=true;
  rep(i, n){
    int u, k; cin >> u >> k;
    d[i] = 1000000000;
    rep(j, k){
      int v, c; cin >> v >> c;
      g[i].push_back({v, c});
    }
  }
  d[0] = 0;
  while(flag){
    flag = false;
    rep(i, n){
      rep(j, g[i].size()){
        int check = d[g[i][j].to];
        d[g[i][j].to] = min(d[i]+g[i][j].cost, d[g[i][j].to]);
        if(check != d[g[i][j].to])  flag = true;
        cout << "debug : " << i << " " << g[i][j].to << " " << d[g[i][j].to] << endl;
       }
    }
  }
  rep(i, n) cout << i << " "<< d[i] << endl;
  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

const int MAX = 100;
const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;
int n, M[MAX][MAX];

int dijkstra()
{
	int minv;
	int d[MAX];
	int color[MAX];

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

	d[0] = 0;
	color[0] = GRAY;

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

		if (u == -1) break;
		color[u] = BLACK;
		for (int v = 0; v < n; v++) {
			if (M[u][v] != INF && color[v] != BLACK) {
				if (d[v] > d[u] + M[u][v]) {
					d[v] = d[u] + M[u][v];
					color[v] = GRAY;
				}
			}
		}
	}

	for (int i = 0; i < n; i++) {
		cout << i << " " << (d[i] == INF ? -1 : d[i]) << endl;
	}

	return 0;
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			M[i][j] = INF;

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

	dijkstra();

	return 0;
}

C++: #include<iostream>

using namespace std;

static const int N = 100;
static const int I=(1<<21);
static const int W= 0;
static const int G =1;
static const int B =2;

int n,M[N][N];

int dij(){
  int minv,d[N],color[N];
  for(int i=0;i<n;i++){
    d[i]=I;
    color[i]=W;
  }

  d[0]=0;
  color[0]=G;

  while(1){
    minv=I;
    int u=-1;
    for(int i=0;i<n;i++){
      if(minv>d[i]&&color[i]!=B){
        u=i;
        minv=d[i];
      }
    }
    if(u==-1)break;
    color[u]=B;
    for(int v=0;v<n;v++){
      if(color[v]!=B&&M[u][v]!=I){
        if(d[v]>d[u]+M[u][v]){
          d[v]=d[u]+M[u][v];
          color[v]=G;
        }
  
      
          
      }
      }
        
    }
  for(int i=0;i<n;i++){
    cout<<i<<" "<<(d[i]==I ? -1 : d[i])<<endl;
  }
}

int main(){
  cin>>n;

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      M[i][j]=I;
    }
  }

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

  dij();
  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#define INF 1<<10
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<cstdio>
#include<cstring>
#include<queue>
#include<vector>
using namespace std;
const int maxn=10010;
const int Max=10000001;
int n;
int dis[maxn];
bool vis[maxn];

struct edge
{
	int u,v,w;
	edge(int u=0,int v=0,int w=Max):u(u),v(v),w(w){}
};
vector<edge> G[maxn];

struct node
{
	int d,id;
	bool operator < (const node& rhs) const
	{
		return d>rhs.d;
	}
	node(int d=0,int id=0):d(d),id(id){}
};
priority_queue<node> Q;

void dijkstra(int s)
{
	memset(dis,0x7f,sizeof(dis));
	memset(vis,0,sizeof(vis));
	dis[s]=0;
	Q.push(node(0,s));
	while(!Q.empty())
	{
		node u=Q.top();
		Q.pop();
		if(vis[u.id]) continue;
		vis[u.id]=1;
		for(unsigned int i=0;i<G[u.id].size();++i)
		{
			edge e=G[u.id][i];
			if(dis[e.v]>dis[u.id]+e.w)
			{
				dis[e.v]=dis[u.id]+e.w;
				Q.push(node(dis[e.v],e.v));
			}
		}
	}
}

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

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;++i)
	{
		int id,k;
		scanf("%d%d",&id,&k);
		for(int j=0;j<k;j++)
		{
			int v,w;
			scanf("%d%d",&v,&w);
			G[id].push_back(edge(id,v,w));
		}
	}
	dijkstra(0);
	print();
	return 0;
}