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 rep(i,N) for(int i = 0; i<(int)(N); i++)
#define REP(i,k,N) for(int i = k; i<(int)(N); i++)
#define INF 100000+1
typedef long long ll;
using namespace std;
 
int main(){
        int n;
        cin >> n;
        int d[100][100];
        rep(i,100) rep(j,100) d[i][j]=INF;
        int u,k,v,c;
        rep(i,n){
                cin >> u >>k;
                rep(j,k){
                        cin >> v >> c;
                        d[u][v] = c;
                }
        }

        ll l[n];
        rep(i,n) l[i]=INF*n;
        l[0]=0;
        bool update = true;
        while(update) {
                update  = false;
                rep(from,n) rep(to,n){
                        if(l[to] > l[from]+d[from][to]) {
                                update = true;
                                l[to] = l[from]+d[from][to];
                        }
                }
        }
        rep(i,n){
                cout << i << " " << l[i] << endl;
        }

        return 0;
}

C++: #include<vector>
#include<iostream>
#include<algorithm>
#define MAX_V 100
#define INF 1e9
using namespace std;
int cost[MAX_V][MAX_V];
int d[MAX_V];
int used[MAX_V];
int V;//頂点の数

void dijkstra(int s)
{
	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()
{
	
	cin >> V;
	for (int i = 0; i < MAX_V; i++)

	{
		d[i] = INF;
		used[i] = false;

	
	
	
	}
	for (int i = 0; i < MAX_V; i++)
	{
		for (int j = 0; j < MAX_V; j++)

		{
			cost[i][j] = INF;
		}
	}





	for (int i = 0; i < V; i++)
	{
		int u;
		cin >> u;
		int k;
		cin >> k;
		for (int i = 0; i < k; i++)

		{
			int v_to;
			cin >> v_to;
			int c;
			cin >> c;
			cost[u][v_to] = c;

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

}

C++: #include <iostream>
using namespace std;
#define N 100
#define INFTY (1<<21)
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];

void dijkstra() {
    int minv;
    int d[N], color[N];

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

    d[0] = 0;
    color[0] = GRAY;
    while(1) {
        minv = INFTY;
        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(color[v]!=BLACK && M[u][v]!=INFTY) {
                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]==INFTY ? -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] = INFTY;
        }
    }

    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>
#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 <stdio.h>

using namespace std;


int main(){
	int n,count=0,t,min,min_index,tmp,left_node,right_node,dist;
	scanf("%d",&n);
	int distance[n][n],P[n];

	for(int i=0;i<n;i++){
		for(int k=0;k<n;k++)distance[i][k]=100001;
		P[i]=0;
	}
	distance[0][0] = 0;
	P[0]=1;

	for(int i=0;i<n;i++){
		scanf("%d %d",&left_node,&tmp);
		for(int k=0;k<tmp;k++){
			scanf("%d %d",&right_node,&dist);
			distance[left_node][right_node] = dist;
		}
	}

	while(count<n-1){

		min=100001;
		for(int i=1;i<n;i++){
			if(P[i]==0&&distance[0][i]<min){
				min_index = i;
				min = distance[0][i];
			}
		}
		t = min_index;
		P[t]=1;
		count++;

		for(int i=0;i<n;i++){
			if(distance[0][i] > distance[0][t]+distance[t][i]){
				distance[0][i]=distance[0][t]+distance[t][i];
			}
		}
	}

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

    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<set> 
#include<queue>
#include<cstdlib>
using namespace std;

 
int main()
{
	int n;
	scanf("%d",&n);
	int vv[105][105]={0},ans[105]={0},vis[105]={0};
	for(int i=0;i<n;i++)
	{
		int x,y;
		scanf("%d %d",&x,&y);
		while(y--)
		{
			int a,b;
			scanf("%d %d",&a,&b);
			vv[x][a]=b;
		}
	} 
	fill(ans,ans+n,2000000000);
	ans[0]=0;
	while(1)
	{
		int v=-1;
		for(int u=0;u<n;u++)
		{
			if(vis[u]==0&&(v==-1||(ans[u]<ans[v]&&ans[u]!=0))) v=u;
		}
		if(v==-1) break;
		vis[v]=1;
		for(int u=0;u<n;u++)
		{
			if(vv[v][u]!=0) ans[u]=min(ans[u],ans[v]+vv[v][u]);
		}
	}
	for(int i=0;i<n;i++)
	{
		printf("%d %d\n",i,ans[i]);
	} 
	
	return 0;
}

C++: #include<iostream>
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] = 200001;
  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;
}