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<cstdio>
#include<climits>
using namespace std;

#define N 130
int n;

int g[N][N];

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

//prim
void prim(){

  int v;
 
  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;
 

    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;
      }
    }
  }
 
}


int main(){

  int u,k1,c,v;

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

  //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 <iostream>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#include <cmath>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)

#define debug(x) cerr<<#x<<": "<<x<<'\n'

#define fi first
#define se second

#define vi vector<int>
#define pb push_back
#define mp make_pair

#define pcnt __builtin_popcount

typedef long long ll;

const int inf = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

struct Edge{
    int to;
    int cost;
}
vector<int> G[110];
int d[110] = {};
int main(){
    int n;
    cin >> n;
    rep(i,n){
        int t,m;
        cin >> t >> m;
        rep(j,m){
            int a,b;
            cin >> a >> b;
            G[t].push_back({a,b})
        }
    }

    rep(i,n) d[i] = 900010000;
    d[0] = 0;
    while(true){
        bool update = false;
        rep(i,n){
            rep(j,G[i].size()){
                if(d[i] + G[i][j].cost < d[G[i][j].to]){
                    d[G[i][j].to] = d[i]+G[i][j].cost;
                    update = true;
                }
            }
        }
        if(!update) break;
    }

    rep(i,n){
        cout << i << " " << d[i] << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <vector>
#define INF 1<<30
#define WHITE 0
#define GRAY 1
#define BLACK 2
int G[101][101];
using namespace std;
int n;

void prim(int *d, int *pi){
    int color[n];
    int u = 0;
    for (int i = 0; i < n; i++){
        d[i] = pi[i] = INF;
        color[i] = WHITE;
    }
    d[0] = 0;
    while (1){
        int mincost = INF;
        for (int i = 0; i < n; i++){
            if (color[i] != BLACK && d[i] < mincost){
                mincost = d[i];
                u = i;
            }
        }
        if (mincost == INF) break;
        color[u] = BLACK;
        for (int v = 0; v < n; v++){
            int w = G[u][v];
            if (w == -1) continue;
            else if (color[v] != BLACK && d[u]+w < d[v]){
                pi[v] = u;
                d[v] = d[u] + w;
            }
        }
    }
}

int main(int argc, char* argv[]) {
    cin >> n;
    int d[n], pi[n], sum = 0;
    int u, k, v, c;

    //initialize
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            G[i][j] = -1;
        }
    }
    //input
    for (int i = 0; i < n; i++){
        cin >> u >> k;
        for (int j = 0; j < k; j++){
            cin >> v >> c;
            G[u][v] = c;
        }
    }
    prim(d, pi);
    for (int i = 0; i < n; i++){
        cout << i << " " << d[i] << endl;
    }
    return 0;
}

C++: #include <iostream>

using namespace std;

#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INFTY 999999999999999

int color[MAX];
int M[MAX][MAX];
int d[MAX];
int p[MAX];
int n;

int dijkstra(int s)
{

	int mincost;
	int u;

	for (int i = 0; i < n; i++) {
		d[i] = INFTY;
		p[i] = -1;
	}
	d[s] = 0;

	while (true) {
		mincost = INFTY;

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

		if (mincost == INFTY) {
			break;
		}

		color[u] = BLACK;

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


	}


	int sum = 0;

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

	return sum;


}

int main(void)
{

	cin >> n;

	int u;
	int k;
	int v;

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

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

	return 0;
}

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

int n;
const int INF = 1000000;
vector<vector<int> > v, c;
vector<int> w;

void trip(int id, int dp) {
	if (dp > n)
		return;

	for (int j = 0; j < (int)v[id].size(); j++) {
		if (w[v[id][j]] > w[id] + c[id][j])
			w[v[id][j]] = w[id] + c[id][j];
		trip(v[id][j], dp + 1);
	}
}

int main()
{
	cin >> n;

	int u, k, v1, c1;
	v.resize(n);
	c.resize(n);
	w.assign(n, INF);

	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			cin >> v1 >> c1;
			v[u].push_back(v1);
			c[u].push_back(c1);
		}
	}

	w[0] = 0;
	trip(0, 1);

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

	return 0;
}