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 <bits/stdc++.h>

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
const int INF = 1e9;

using namespace std;
int n;
int res = 0;
struct node {
    int id;
    int dist;
    bool searched;
};

node v[100];
int edge[100][100];

int main() {
    cin >> n;
    REP(i, n) {
        int u, k;
        cin >> u >> k;
        v[u].id = u;
        v[u].dist = INF;
        v[u].searched = false;
        REP(j, n) edge[i][j] = INF;
        REP(j, k){
            int to, cost;
            cin >> to >> cost;
            edge[i][to] = cost;
        }
    }
    v[0].dist = 0;
    int next = 0;
    int prev = 0;
    REP(i, n){
        int minimum = INF;
        REP(j, n){
            if(!v[j].searched && edge[prev][j] != INF){
                v[j].dist = min(v[j].dist, v[prev].dist + edge[prev][j]);
                if(minimum >= v[j].dist){
                    next = j;
                    minimum = v[j].dist;
                }
            }
        }
        v[prev].searched = true;
        prev = next;
    }
    REP(i, n) cout << i << " " << v[i].dist << endl;
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<climits>
using namespace std;

#define N 120
int n;

int g[N][N];

int weight[N];
bool us[N];

int prim(){

  int v;
  int ans=0;
  weight[0]=0;
  
  while(true){
    v=-1;
   
    for(int i=0;i<n;i++){
      if(us[i]!=true && (v==-1 ||weight[i]<weight[v]))v=i;
    }

    if(v==-1)break;
    us[v]=true;
    ans+=weight[v];

    for(int i=0;i<n;i++){
      if(weight[i]>(g[v][i]+weight[v])){

        weight[i]=(g[v][i]+weight[v]);
        //      cout <<"fsafa"<<endl;
      }
    }
  }
  return ans;
}


int main(){

  int u,k1,c,v;

  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      g[i][j]=53535;
    }
  }

//load n
  cin >>n;

  //load data
  for(int i=0;i<n;i++){
    weight[i]=INT_MAX;
    us[i]=false;
    scanf("%d %d",&u,&k1);
    for(int j=0;j<k1;j++){
      scanf("%d %d",&v,&c);
      g[u][v]=c;
      //    cout <<g[i][j]<<" ";
    }
    //    cout <<endl;
  }




  //print
  prim();

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

}

C++: #include <bits/stdc++.h>
using namespace std;
#define MAX 101
#define INF 100100

static const int WHITE = 0; //not visited
static const int GRAY = 1; //visited
static const int BLACK = 2;

int n, M[MAX][MAX];
int color[MAX];
int dist_from_start[MAX];
int parent_node[MAX];

void dijkstra(int start) {
  //initialize
  for (int i = 1; i <= n; i++) {
    color[i] = WHITE;
    dist_from_start[i] = INF;
    parent_node[i] = -1;
  }

  dist_from_start[start] = 0;
  color[start] = GRAY;

  while (true) {
    int mincost = INF;
    int now = -1;

    //初回はmincost = 0になる(始点)
    for (int i = 1; i <= n; i++) {
      if (color[i] != BLACK && dist_from_start[i] < mincost) {
        mincost = dist_from_start[i];
        now = i;
      }
    }

    if (now == -1) break;

    color[now] = BLACK;

    for (int v = 1; v <= n; v++) {
      if (color[v] != BLACK && M[now][v] != INF) {
        if (dist_from_start[now] + M[now][v] < dist_from_start[v]) {
          dist_from_start[v] = dist_from_start[now] + M[now][v];
          parent_node[v] = now;
          color[v] = GRAY;
        }
      }
    }
  }

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

int main() {
  cin >> n;

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

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

  dijkstra(1);

  return 0;
}

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

vector<vector<pair<int, int>>> v;
vector<int> d, color;

const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;

void dijkstra(){
  priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
  q.push(make_pair(0, 0));
  d[0] = 0;

  while(!q.empty()){
    auto next = q.top(); q.pop();
    if(color[next.second] == BLACK) continue;

    color[next.second] = BLACK;

    for(auto ve : v[next.second]){
      if(color[ve.first] != BLACK && d[ve.first] > d[next.second] + ve.second){
        d[ve.first] = d[next.second] + ve.second;
        color[ve.first] = GRAY;
        q.push(make_pair(d[ve.first], ve.first));
      }
    }
  }
}

int main(){
  int n; cin >> n;

  v.resize(n);
  d.resize(n);
  color.resize(n);

  for(int i=0; i<n; ++i){
    d[i] = numeric_limits<int>::max();

    int u, k, ve, c; cin >> u >> k;
    for(int l=0; l<k; ++l){
      cin >> ve >> c;
      v[u].push_back(make_pair(ve, c));
    }
  }

  dijkstra();

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

C++: #include <cstdio>
#include <queue>
#include <utility>
using namespace std;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;
vector<pair<int, int>> adj[100];
int *d;

void dijkstra() {
    priority_queue<pair<int, int>> PQ;
    int d[n], color[n];

    for (int i = 0; i < n; i++) {
        d[i] = INFTY;
        color[n] = WHITE;
    }
    d[0] = 0;
    PQ.push(make_pair(0, 0));

    while (!PQ.empty()) {
        pair<int, int> f = PQ.top();
        PQ.pop();

        int u = f.second;
        color[u] = BLACK;

        if (d[u] < f.first * (-1)) { continue; }

        for (int j = 0; j < adj[u].size(); j++) {
            int v = adj[u][j].first;
            if (color[v] == BLACK) { continue; }
            if (d[u] + adj[u][j].second < d[v]) {
                d[v] = d[u] + adj[u][j].second;
                // printf("d[%d] = %d\n", v, d[v]);
                PQ.push(make_pair(d[v] * (-1), v));
                color[v] = GRAY;
            }
        }
    }
    
    for (int i = 0; i < n; i++) {
        printf("%d %d\n", i, d[i]);
    }
}

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

    // adj = new vector<pair<int, int>>[n];

    for (int i = 0; i < n; i++) {
        int u, k;
        scanf("%d %d", &u, &k);
        for (int j = 0; j < k; j++) {
            int v, c;
            scanf("%d %d", &v, &c);
            adj[u].push_back(make_pair(v, c));
        }
    }

    dijkstra();

    return 0;
}