Go: package main

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

const MAX = 100
const INFTY = math.MaxInt64
const WHITE = 0
const GRAY = 1
const BLACK = 2

var n int
var M [MAX][MAX]int

func dijkstra() {
	var minv int
	var d [MAX]int
	var color [MAX]int

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

	d[0] = 0
	color[0] = GRAY
	for {

		minv = INFTY
		u := -1
		for 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 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 i := 0; i < n; i++ {
		fmt.Printf("%v %v\n", i, d[i])
	}
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ = strconv.Atoi(sc.Text())

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

	for i := 0; i < n; i++ {
		sc.Scan()
		f, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())
		for j := 0; j < k; j++ {
			sc.Scan()
			v, _ := strconv.Atoi(sc.Text())
			sc.Scan()
			c, _ := strconv.Atoi(sc.Text())
			M[f][v] = c
		}
	}
	dijkstra()
}

C++: #include <iostream>
#include <vector>
#include<climits>

using namespace std;

int n;
vector<int> g[100];
vector<int> w[100];
int d[100];
char color[100];

void dijkstra() {
    d[0] = 0;
    color[0] = 'b';

    for (int k = 1; k < n; ++k) {
        int next;
        int mine = INT_MAX;
        for (int i = 0; i < n; ++i) {
            if (color[i] == 'b') {
                for (int j = 0; j < g[i].size(); ++j) {
                    if (d[i] + w[i].at(j) <= d[g[i].at(j)] && color[g[i].at(j)] == 'w') {
                        d[g[i].at(j)] = d[i] + w[i].at(j);
                        if (d[g[i].at(j)] <= mine) {
                            next = g[i].at(j);
                            mine = d[next];
                        }
                    }
                }
            }
        }
        color[next] = 'b';
        d[next] = mine;
    }
}

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int u;
        int k;
        cin >> u >> k;
        int v, c;
        for (int j = 0; j < k; ++j) {
            cin >> v >> c;
            g[u].push_back(v);
            w[u].push_back(c);
        }
    }
    for (int m = 0; m < n; ++m) {
        color[m] = 'w';
        d[m] = INT_MAX;
    }

    dijkstra();

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

    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<cstring>
#define P pair<int,int>//cost to
using namespace std;

vector<P>rinsetu[100];
int mincost[100];
signed main() {
	int a; cin >> a;
	for (int b = 0; b < a; b++) {
		int c, d; cin >> c >> d;
		for (int e = 0; e < d; e++) {
			int f, g; scanf("%d%d", &f, &g);
			rinsetu[c].push_back(P(g,f));
		}
	}
	fill(mincost, mincost + a, 1 << 29);
	mincost[0] = 0;
	priority_queue<P, vector<P>, greater<P>>Q;
	Q.push(P(0,0));
	while (Q.size()) {
		P t = Q.top(); Q.pop();
		if (t.first > mincost[t.second])continue;
		for (P i : rinsetu[t.second]) {
			if (mincost[i.second] > t.first + i.first) {
				mincost[i.second] = t.first + i.first;
				Q.push(P(t.first + i.first,i.second));
			}
		}
	}
	for (int i = 0; i < a; i++) {
		cout << i << " " << mincost[i] << endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <numeric>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

int main(){
    int n;cin>>n;
    vector<vector<int>> v(n,vector<int>(n,INF));
    rep(i,0,n)v[i][i]=0;
    rep(i,0,n){
        int u,k; cin>>u>>k;
        rep(j,0,k){
            int to,cost;
            cin>>to>>cost;
            v[u][to]=cost;
        }
    }
    
    rep(i,0,n){
        rep(j,0,n){
            rep(k,0,n){
                v[j][k]=min(v[j][k],v[j][i]+v[i][k]);
            }
        }
    }
    rep(i,0,n){
        cout<<i<<" "<<v[0][i]<<endl;
    }
    
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
long long INF = 1000000000000000;
vector<long long> bellman_ford(vector<vector<pair<int, int>>> &E, int s){
    int V = E.size();
    vector<long long> d(V, INF);
    d[s] = 0;
    while (1){
        bool update = false;
        for (int i = 0; i < V; i++){
            for (int j = 0; j < E[i].size(); j++){
                int c = E[i][j].first;
                int v = E[i][j].second;
                if (d[v] > d[i] + c && d[i] != INF){
                    d[v] = d[i] + c;
                    update = true;
                }
            }
        }
        if (!update){
            break;
        }
    }
    return d;
}
int main(){
    int n;
    cin >> n;
    vector<vector<pair<int, int>>> E(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;
            E[i].push_back(make_pair(c, v));
        }
    }
    vector<long long> d = bellman_ford(E, 0);
    for (int i = 0; i < n; i++){
        cout << i << ' ' << d[i] << endl;
    }
}

C++: #include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

struct edge {int to, cost;};

int main(void){
    int n;
    cin >> n;
    vector<edge> d[n];
    rep(i, n){
        int u, k;
        cin >> u >> k;
        rep(j, k){
            int v, c;
            cin >> v >> c;
            d[u].push_back({v, c});
        }
    }
    vector<int> v(n);
    fill(v.begin(), v.end(), INT_MAX);
    priority_queue<P,vector<P>, greater<P>> q;
    q.push({0, 0});
    while(!q.empty()){
        P p = q.top(); q.pop();
        int g = p.second;
        if(v[g] < p.first) continue;
        v[g] = p.first;
        for(auto x : d[g]){
            if(v[x.to] > v[g] + x.cost)
                q.push({v[g] + x.cost, x.to});
        }
    }
    rep(i, n) cout << i << ' ' << v[i] << endl;
    return 0;
}

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

int n;
vector< vector<int> > G;
vector<int> color, d, p;

void Dijsktra() {
  color.resize(n), d.resize(n, 1000000000), p.resize(n, -1);
  d[0] = 0;

  while (true) {
    int min_cost = 1000000000, u;
    for (int i = 0; i < n; i++) if (color[i] != 2 && d[i] < min_cost) min_cost = d[i], u = i;
    if (min_cost == 1000000000) break;
    color[u] = 2;
    for (int v = 0; v < n; v++) {
      if (color[v] != 2 && G[u][v] != -1)
        if (d[u] + G[u][v] < d[v]) d[v] = d[u] + G[u][v], p[v] = u, color[v] = 1;
    }
  }
}

int main() {
  cin >> n;
  G.resize(n, vector<int>(n, -1));
  for (int i = 0; i < n; i++) {
    int u, k;
    cin >> u >> k;
    for (int i = 0; i < k; i++) {
      int v, c;
      cin >> v >> c;
      G[u][v] = c;
    }
  }

  Dijsktra();

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