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 <algorithm>
#define N 100
#define INF 2000000000
using namespace std;

int n, M[N][N], d[N], color[N] = {0};

void Dijk(int s) {
	int min;
	while (true) {
		int u;
	    min = INF;
		for (int i = 0;i < n;i++) d[i] = INF;
		d[s] = 0;

		for (int i = 0;i < n;i++) {
			if (color[i] == 0 && d[i] < min)
				min = d[i];
			u = i;
		}

		if (min == INF) break;

		color[u] = 1;

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

	for(int i=0;i<n;i++)
	cout<<i<<" "<<d[i]<<endl;

}

int main() {

	for (int i = 0;i < N;i++)
		for (int j = 0;j < N;j++) M[i][j] = INF;

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

	Dijk(0);

}

C++: #include <cstdio>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>

using namespace std;

int main() {

	int INF = 100001;

	int n;
	scanf("%d", &n);

	vector<pair<int, int>> G[n];
	for (int i = 0; i < n; ++i) {
		int from;
		scanf("%d", &from);

		int v;
		scanf("%d", &v);

		for (int j = 0; j < v; ++j) {
			int to;
			int w;
			scanf("%d %d", &to, &w);
			G[from].push_back(make_pair(to, w));
		}
	}

	int C[n];
	for (int i = 0; i < n; ++i)
		C[i] = INF;

	int color[n];
	int WHITE = 0;
	int BLACK = 1;
	for (int i = 0; i < n; ++i)
		color[i] = WHITE;

	priority_queue<pair<int, int>> PQ;
	PQ.push(make_pair(0, 0));
	C[0] = 0;
	while (!PQ.empty()) {
		int u = PQ.top().second;
		PQ.pop();
		color[u] = BLACK;
		for (int i = 0; i < (int) G[u].size(); ++i) {
			auto c = G[u][i];
			if (color[c.first] != BLACK && c.second + C[u] < C[c.first]) {
				C[c.first] = c.second + C[u];
				PQ.push(make_pair(C[c.first] * -1, c.first));
			}
		}
	}

	for (int i = 0; i < n; ++i) {
		cout << i << " " << C[i] << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
#define INF 10000000

int main(){
  int n,k,ti,tv,tc;
  int d[100];
  vector<int> v[100],w[100];
  
  int minc,mi,i;
  bool flg[100];
  
  cin >> n;
  for (i=0;i<n;i++){
    cin >>ti>>k;
    for (int j=0;j<k;j++){
      cin >> tv>>tc;
      v[ti].push_back(tv);
      w[ti].push_back(tc);
    }
    d[i]=INF;
    flg[i]=false;
  }

  d[0]=0;
  while (true){
    minc=INF;
    for (i=0;i<n;i++){
      if (!flg[i]&&d[i]<minc){
	minc=d[i];
	mi=i;
      }
    }

    for (i=0;i<n;i++){
      //cout << d[i] << " ";
    }
    //cout <<" :" << mi << endl;
    if (minc==INF) break;
    flg[mi]=true;
    for (i=0;i<v[mi].size();i++){
      if (!flg[v[mi][i]]&&d[v[mi][i]]>d[mi]+w[mi][i]){
	//cout <<v[mi][i] <<" "<<d[mi]+w[mi][i] << endl;
	d[v[mi][i]]=d[mi]+w[mi][i];
      }
    }
  }
  
  for (i=0;i<n;i++){
    cout << i <<" "<<d[i]<<endl;
  }
  
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define INF 1000000000
int main(){
  int n,c,u,k,v,G[100][100],used[100]={},d[100]={},min=0;
  
  cin>>n;
  for(int i=1;i<n;i++)
    d[i]=INF;

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

  while(min!=INF){
    min=INF;
    int idx;
    for(int i=0;i<n;i++)
      if(used[i]!=1 && d[i]<min){
	min=d[i];
        idx=i;
      }
    for(int i=0;i<n;i++)
      if(G[idx][i]!=-1 && used[i]!=1 && d[idx]+G[idx][i]<d[i])d[i]=d[idx]+G[idx][i];
    used[idx]=1;
  }
  
  for(int i=0;i<n;i++)
    cout<<i<<' '<<d[i]<<endl;

  return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#define MAX_V 100
#define INF 1e9
using namespace std;
int cost[MAX_V][MAX_V];
int d[MAX_V];
bool used[MAX_V];
int V;
void dijkstra(int s) {
	for (int i = 0; i < MAX_V; i++) {
		d[i] = INF;
		used[i] = false;
	}
	d[s] = 0;
	while (true) {
		int v = -1;
		for (int u = 0; u < V; u++) {
			if (!used[u] && ((v == -1) || d[u] < d[v])) {
				v = u;
			}
		}
		//全ての頂点が到達済み
		if (v == -1) {
			break;
		}
		//集合に新たに頂点を追加
		used[v] = true;
		for (int u = 0; u < V; u++) {
			d[u] = min(d[u], d[v] + cost[v][u]);
		}
	}
}

int main() {
	for (int i = 0; i < MAX_V; i++) {
		for (int j = 0; j < MAX_V; j++) {
			cost[i][j] = INF;
		}
	}
	cin >> V;
	for (int i = 0; i < V; i++) {
		int u;
		cin >> u;
		int k;
		cin >> k;
		for (int j = 0; j < k; j++) {
			int v;
			cin >> v;
			int c;
			cin >> c;
			cost[u][v] = c;
		}
	}
	dijkstra(0);

	for (int i = 0; i < V; i++) {
		cout << i << " " << d[i] << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
#include<stdio.h>

int main()
{
    int n, m, i, j, a, w;
    int* adj[100];
    int* dist[100];
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%d %d", &i, &m);
        adj[i] = new int [m + 1];
        dist[i] = new int [m + 1];
        for(j = 0; j < m; j++){
            scanf("%d %d", &a, &w);
            adj[i][j] = a;
            dist[i][j] = w;
        }
        adj[i][m] = -1;
        dist[i][m] = -1;
    }
    int *d, *prev, *Q;
    d = new int [n];
    prev = new int [n];
    Q = new int [n];
    for(i = 0; i < n; i++){ d[i] = 200000; prev[i] = -1; Q[i] = i; }
    int rest = n;

    int u, v, min;
    d[0] = 0;
    while(rest > 0){
        min = 200000;
        for(i = 0; i < n; i++){
            if(min > d[i] && Q[i] >= 0){ min = d[i]; u = i; }
        }
        Q[u] = -1;
        rest--;

        for(j = 0; adj[u][j] >= 0; j++){
            v = adj[u][j];
            if(d[v] > d[u] + dist[u][j]){
                d[v] = d[u] + dist[u][j];
                prev[v] = u;
            }
        }
    };
    for(i = 0; i < n; i++){ printf("%d %d\n", i, d[i]); }
    for(i = 0; i < n; i++){
        delete adj[i]; delete dist[i]; }
    delete d;
    delete prev;
    delete Q;
 
    return 0;
}