Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

const T = 10000000

var n int
var A [101][101]int

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func Shortestsearch() {
	var Minimum int
	var d, color [100]int
	var u int

	for i := 0; i < n; i++ {
		d[i] = T
		color[i] = 0
	}

	d[0] = 0
	color[0] = 1

	for {
		Minimum = T
		u = -1
		for i := 0; i < n; i++ {
			if Minimum > d[i] && color[i] != 2 {
				u = i
				Minimum = d[i]
			}
		}
		if u == -1 {
			break
		}
		color[u] = 2
		for j := 0; j < n; j++ {
			if color[j] != 2 && A[u][j] != T {
				if d[j] > d[u]+A[u][j] {
					d[j] = d[u] + A[u][j]
					color[j] = 1
				}
			}
		}
	}
	for i := 0; i < n; i++ {
		fmt.Printf("%d %d\n", i, d[i])
	}
}
func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()

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

C++: #include<iostream>
#include<vector>
#define MAX 1000000
using namespace std;
static const int N = 100;
int A[N][N],d[N],p[N],color[N]={0};
void algo(int);
void print(int);
int main(void){
    int n,u,k,v,c;
    cin >> n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            A[i][j] = -1;
        }
    }
    for(int i=0;i<n;i++){
        cin >> u >> k;
        if(k!=0){
            for(int j=1;j<=k;j++){
                cin >> v >> c;
                A[u][v] = c;
            }
        }
    }
    for(int i=0;i<n;i++){
        d[i] = MAX;
        p[i] = 0;
    }
    d[0] = 0;
    algo(n);
    print(n);
    return 0;
}
void algo(int n){
    vector<int> S;
    while(S.size()!=n){
        int min = MAX,u =-1;
        for(int i=0;i<n;i++){
            if(min>d[i] && color[i]!=1){
                min= d[i];
                u= i;
            }
        }
        color[u] = 1;
        S.push_back(u);
        for(int v=0;v<n;v++){
            if(d[u]+A[u][v]<d[v] && A[u][v]!=-1){
                d[v] = d[u] + A[u][v];
                p[v] = u;
            }
        }
    }
}
void print(int n){
    for(int i=0;i<n;i++){
        cout << i << ' ' << d[i] << endl;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;

const int INF = 1 << 21;
const int MAX = 103;
const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;
int n, G[MAX][MAX];

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

  fill((int*)d, (int*)(d+MAX), INF);
  memset(color, WHITE, sizeof(color));

  d[0] = 0;
  color[0] = GRAY;
  while (true) {
    minv = INF;
    int u = -1;
    rep(i,n) {
      if (minv > d[i] && color[i] != BLACK) {
	u = i;
	minv = d[i];
      }
    }
    if (u == -1) break;
    color[u] = BLACK;
    rep(v,n) {
      if (color[v] != BLACK && G[u][v] != INF) {
	if (d[v] > d[u] + G[u][v]) {
	  d[v] = d[u] + G[u][v];
	  color[v] = GRAY;
	}
      }
    }
  }

  rep(i,n) {
    cout << i << ' ' << (d[i] == INF ? -1 : d[i]) << endl;
  }
}

int main() {
  cin >> n;
  rep(i,n) {
    fill((int*)G[i], (int*)(G[i]+n), INF);
  }
  
  int u, k, v, c;
  rep(i,n) {
    cin >> u >> k;
    rep(j,k) {
      cin >> v >> c;
      G[i][v] = c;
    }
  }

  dijkstra();
  return 0;
}

C++: #include<stdio.h>
#define N 100
#define INFTY (1<<21)
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define NON -1

void dijkstra();

int M[N][N],d[N];
int n;

int main(){
  int i,j,u,k,v;
  
  scanf("%d",&n);

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

  
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      scanf("%d",&M[u][v]);
    }
  }

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



void dijkstra(){
  int u,min;
  int i;
  int color[N];

  //初期化
  for(i=0;i<n;i++){
    d[i]=INFTY;
    color[i]=WHITE;
  }
  
  d[0]=0;
  

  while(1){
    min=INFTY;
    u=NON;
    //進路決め
    for(i=0;i<n;i++){
      if(min>d[i] && color[i]!=BLACK){
        u=i;
        min=d[i];
      }
    }
    if(u==NON) break;
    color[u]=BLACK;
    //次の節点の設定
    for(i=0;i<n;i++){
      if(color[i]!=BLACK && M[u][i]!=INFTY)
      if(d[i]>M[u][i]+d[u]){
        d[i]=M[u][i]+d[u];
        color[i]=GRAY;
      }
    }
  }

}

C++: #include <iostream>

using namespace std;
static const int MAX=100;
static const int INFTY= (1<<21);
int M[MAX][MAX]; //?????\??????
int d[MAX]; //?????????????????¬
bool visited[MAX]; //???????¢??????????

void dijkstra(int n)
{
    int min;
    //init
    for(int i=0;i<n;i++)
    {
        visited[i]=false;
        d[i]=INFTY;
    }
    //select node 0
    d[0]=0;
    while(true)
    {
        min=INFTY;
        int min_point=-1;
        for(int i=0;i<n;i++)  //?????????????????????????????\??¶???
        {
            if(min>d[i]&&visited[i]==false)
            {
                min_point=i;
                min=d[i];
            }
        }
        if(min_point==-1) break;  //??????????????°????????????????????????

        visited[min_point]=true;
        //update
        for(int i=0;i<n;i++)
        {
            if(visited[i]==false&&M[min_point][i]!=INFTY)
                if(d[min_point]+M[min_point][i]<d[i])
                    d[i]=d[min_point]+M[min_point][i];
        }
    }
    //print
    for(int i=0;i<n;i++)
        cout<<i<<' '<<(d[i]==INFTY?-1:d[i])<<endl;
}
int main()
{
    int n;
    cin>>n;
    //init
    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++)
    {
        int j;
        cin>>j;
        int nodes_num;
        cin>>nodes_num;
        for(int k=0;k<nodes_num;k++)
        {
            int v,d;
            cin>>v>>d;
            M[j][v]=d;
        }
    }
    dijkstra(n);
}

C++: #include<bits/stdc++.h>
using namespace std;

typedef pair< int, int > Pi;
struct edge{
  int to, cost;
};
typedef vector< vector< edge > > Graph;

int Dijkstra(Graph& info, int s, int g,
             vector< int >& min_cost) {
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  min_cost.resize(info.size(), -1);
  que.push( Pi( 0, s));
  min_cost[s] = 0;
  while(!que.empty()){
    Pi p = que.top(); que.pop();
    if(p.second == g) return p.first;
    if(p.first > min_cost[p.second]) continue;
    for(int i = 0; i < info[p.second].size(); i++){
      edge& e = info[p.second][i];
      if(min_cost[e.to] == -1 ||
         p.first + e.cost < min_cost[e.to]){
        min_cost[e.to] = p.first + e.cost;
        que.push( Pi( min_cost[e.to], e.to));
      }
    }
  }
  return -1;
}
int main(){
  int n;
  cin >> n;
  Graph graph(n);
  vector< int > min_cost;
  for(int i = 0; i < n; i++){
    int u, k;
    cin >> u >> k;
    for(int i = 0; i < k; i++){
      int c, v;
      cin >> v >> c;
      graph[u].push_back( (edge){ v, c});
    }
  }
  Dijkstra( graph, 0, n, min_cost);
  for(int i = 0; i < n; i++){
    cout << i << " " << min_cost[i] << endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;

const int INF = numeric_limits<int>::max();

struct edge {
    int u, v, c;
};
struct Graph {
    vector<edge> es;
    vector<int> d;
    Graph(int n) {
        d.assign(n, INF);
    }
};

int main()
{
    int n;
    cin >> n;
    Graph g(n);
    for (int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int v, c;
            cin >> v >> c;
            g.es.push_back({u, v, c});
        }
    }

    g.d[0] = 0;
    for (int i = 0; i < n - 1; i++) {
        for (edge e : g.es) {
            if (g.d[e.u] != INF && g.d[e.v] > g.d[e.u] + e.c) {
                g.d[e.v] = g.d[e.u] + e.c;
            }
        }
    }

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