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>
using namespace std;
#define INT_MAX 10000000

int M[101][101];
int d[101];
int n;
vector<int> q;

int check(int point){
    if(find(q.begin(), q.end(), point) != q.end()){
        //printf("%d in q\n",point);
        return 1;
    }
    else{
        //printf("%d not in q\n",point);
        return 0;
    }
}

void dijk(int point){
    q.push_back(point);
    int node, mini = INT_MAX;

    while(q.size()!=n){
        mini = INT_MAX;
        for(int i=1;i<n;++i){
            if(mini>d[i] && check(i)==0){
                node = i;
                mini = d[i];
            }
        }
        q.push_back(node);
        //printf("push node %d\n",node);
        for(int i=0;i<n;++i){
            if(d[node]+M[node][i]<d[i]){
                d[i] = d[node]+M[node][i];
            }
        }
    }
}

int main(){
    int id, pair_n, source, dis;
    int value;
    //FILE *fp=fopen("In3.txt","r");
    scanf("%d",&n);
    for(int i=0;i<n;++i){
        for(int j=0;j<n;++j){
            M[i][j] = INT_MAX;
        }
    }
    for(int i=0;i<n;++i){
        scanf("%d %d",&id, &pair_n);
        //cin >> id >> pair_n;
        for(int j=0;j<pair_n;++j){
            scanf("%d %d",&source, &dis);
            //cin >> source >> dis;
            M[id][source] = dis;
        }
    }
    d[0] = 0;
    for(int i=1;i<n;++i){
        d[i] = M[0][i];
    }
    dijk(0);
    for(int i=0;i<n;++i){
        printf("%d %d\n",i,d[i]);
    }

    return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

class Graph
{
public:
    enum
    {
        WHITE = 0,
        GRAY = 1,
        BLACK = 2,
    };

    Graph() {}
    Graph(int n)
    : color(n, WHITE), M(n, vs32(n, INFTY)), d(n, INFTY), p(n, -1)
    {}
    ~Graph() {}

    void prim(int s)
    {
        d[s] = 0;
        
        while (true)
        {
            int minv = INFTY;
            int u = -1;
            rep (i, color.size())
            {
                if (color[i] != BLACK && minv > d[i])
                {
                    minv = d[i];
                    u = i;
                }
            }

            if (u < 0) break;
            d[u] = minv;
            color[u] = BLACK;

            rep (v, color.size())
            {
                if (color[v] != BLACK && d[v] > d[u] + M[u][v])
                {
                    d[v] = d[u] + M[u][v];
                    p[v] = u;
                    color[v] = GRAY;
                }
            }
        }
    }

    static const int INFTY = 1e9;
    vs32 color;
    vector< vs32 > M;
    vs32 d;
    vs32 p;
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    Graph g(n);

    int u, v;
    int w;
    int c;
    rep (i, n)
    {
        cin >> u >> c;
        rep (j, c)
        {
            cin >> v >> w;
            g.M[u][v] = w;
        }
    }

    g.prim(0);
    rep (i, n)
    {
        cout << i << " " << g.d[i] << "\n";
    }
    return 0;
}

C++: #include<stdio.h>
#include<stdlib.h>

#define rep( i ,end ) for( int i = 0 ; i < end ; ++i )
#define Nmax 100
#define INF ( INT_MAX / 10 )

int Node[ Nmax ][ Nmax ] ;

int min( int a ,int b )
{
	return a > b ? b : a ;
}

void Init( int NODE[ Nmax ][ Nmax ] ,int N )
{
	rep( i ,N )
	{
		rep( j ,N )
		{
			NODE[ i ][ j ] = ( i == j ) ? 0 : INF ;
		}
	}
}



int main( void )
{
	int N ,V ,K ;
	int v ,cost ;
	scanf( "%d" ,&N ) ;

	Init( Node ,N ) ;

	rep( i ,N )
	{
		scanf( "%d %d" ,&V ,&K ) ;

		rep( j ,K )
		{
			scanf( "%d %d" ,&v ,&cost ) ;

			Node[ V ][ v ] = cost ;
		}
	}

	rep( u ,N )
	{
		rep( i ,N )
		{
			rep( j ,N )
			{
				Node[ i ][ j ] = min( Node[ i ][ j ] ,Node[ i ][ u ] + Node[ u ][ j ] ) ;
			}
		}
	}

	rep( u ,N )
	{
		printf( "%d %d\n" ,u ,Node[ 0 ][ u ] ) ;
	}

	return 0 ;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>
#include <random>
#include <list>
#include <numeric>



#define rep(i,p,q) for(i = p;i < q;i++)
#define ll long long

using namespace std;

int v, e;



int main(void) {
	cin >> v;

	int i;
	ll d[100][100];
	int j;
	rep(i, 0, 100) {
		rep(j, 0, 100) {
			d[i][j] = i == j ? 0 : 1e11;
		}
	}
	rep(i, 0, v) {
		int u,k;
		cin >> u >> k;
		int i2;
		rep(i2, 0, k) {
			int t, c;
			cin >> t >> c;
			d[i][t] = c;
		}
		
		
	}

	int k;
	bool negative = false;
	rep(i, 0, v) {
		rep(j, 0, v) {
			rep(k, 0, v) {
				if (d[j][i] != 1e11 && d[i][k] != 1e11) {
					d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
				}

			}
		}
	}

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



}

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

struct Node{
    int to, weight;
    Node(int t, int w){
        to = t;
        weight = w;
    };
};

const int inf = 200000;

vector<Node> G[100];
int d[100];
bool color[100];

int main(){
    int n, u, k, v, c, minc, tag;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> u >> k;
        for(int j = 0; j < k; j++){
            cin >> v >> c;
            G[u].push_back(Node(v, c));
        }
        d[i] = inf;
        color[i] = false;
    }
    d[0] = 0;
    while(true){
        minc = inf;
        for(int i = 0; i < n; i++){
            if(!color[i] && d[i] < minc){
                minc = d[i];
                tag = i;
            }
        }
        if(minc == inf) break;
        color[tag] = true;
        for(int i = 0; i < G[tag].size(); i++){
            if(!color[G[tag][i].to] && d[tag] + G[tag][i].weight < d[G[tag][i].to])
                d[G[tag][i].to] = d[tag] + G[tag][i].weight;
        }
    }
    for(int i = 0; i < n; i++) cout << i << " " << d[i] << endl;
    return 0;
}