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(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct edge{int from, to; ll cost;};

map<ll, ll> d;
priority_queue< Pll, vector<Pll>, greater<Pll> > que;
map<ll, vector<Pll> > edges;

void dijkstra(ll start){
    d[start] = 0;
    que.push(Pll(0, start));

    while(!que.empty()){
        Pll v = que.top(); que.pop();
        if(d.find(v.second) != d.end() && d[v.second] < v.first) continue;
        for(Pll e: edges[v.second]){
            if(d.find(e.first) == d.end() || d[e.first] > d[v.second] + e.second){
                d[e.first] = d[v.second] + e.second;
                que.push(Pll(d[e.first], e.first));
            }
        }
    }
}

int main(){
    std::ios::sync_with_stdio(0); cin.tie(0);
    int n;
    ll u, k, c, v;
    cin >> n;
    rep(n){
        cin >> u >> k;
        repp(j, k){
            cin >> v >> c;
            edges[u].emplace_back(v, c);
        }
    }

    dijkstra(0);
    repp(u, n) cout << u << " " << d[u] << endl;

}

C++: #include <iostream>

using namespace std;
static const int mx=107;
static const int inf=(1<<21);

int n,m[mx][mx];

void dijkstra()
{
	int minv;
	int d[mx],color[mx];
	
	for (int i=0;i<n;i++) {
		d[i]=inf;
		color[i]=0;
	}
	
	d[0]=0;
	color[0]=1;
	while (1) {
		minv=inf;
		int u=-1;
		for (int i=0;i<n;i++) {
			if(minv>d[i]&&color[i]!=2)
			{
				u=i;
				minv=d[i];
			}
		}
		if(u==-1)break;
		color[u]=2;
		for (int v=0;v<n;v++) {
			if(color[v]!=2&&m[u][v]!=inf)
			{
				if(d[v]>d[u]+m[u][v])
				{
					d[v]=d[u]+m[u][v];
					color[v]=1;
				}
			}
		}
	}
		for (int i=0;i<n;i++) 
			cout<<i<<" "<<(d[i]==inf?-1:d[i])<<endl;
}
int main(int argc, char *argv[]) {
	cin>>n;
	for (int i=0;i<n;i++) {
		for (int j=0;j<n;j++) {
			m[i][j]=inf;
		}
	}
	int k,c,u,v;
	for (int i=0;i<n;i++) {
		cin>>u>>k;
		for (int j=0;j<k;j++) {
			cin>>v>>c;
			m[u][v]=c;
		}
	}
		
	dijkstra();
	
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define int long long
int e[111][111],d[111],used[111];
signed main(){
  int n;
  cin>>n;
  int INF=1LL<<55LL;
  fill((int*)e,(int*)(e+111),INF);
  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[u][v]=min(e[u][v],c);
    }
  }
  memset(used,0,sizeof(used));
  for(int i=0;i<n;i++)d[i]=INF;
  d[0]=0;
  while(1){
    int u=-1;
    for(int i=0;i<n;i++){
      if(used[i])continue;
      if(d[i]==INF)continue;
      if(u<0||d[i]<d[u])u=i;
    }
    if(u<0)break;
    used[u]=1;
    for(int i=0;i<n;i++)d[i]=min(d[i],d[u]+e[u][i]);
  }
  for(int i=0;i<n;i++)cout<<i<<" "<<d[i]<<endl;
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define END return 0
typedef int64_t ll;
const int mod7 = 1e9 + 7;
const int mod9 = 1e9 + 9;
const int inf = 1 << 30;
const ll INF = 1LL << 60;
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a % b) : abs(a);}
template<typename T> T lcm(T a, T b) {return a / gcd(a, b) * b;}
template<typename T> bool chmax(T &a, T b) {if (a < b) {a = b; return true;} return false;}
template<typename T> bool chmin(T &a, T b) {if (a > b) {a = b; return true;} return false;}
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) {fill((T*)array, (T*)(array+N), val);}

int n;
using P = pair<int, int>;
int l[100][100];
int d[100];

void dijkstra(int start) {
    fill(d, d + 100, inf);
    d[start] = 0;
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    while(!que.empty()) {
        P p = que.top();
        que.pop();
        rep(i, n)
            if(chmin(d[i], p.first + l[p.second][i]))
                que.push({d[i], i});
    }
}

int main() {
    Fill(l, inf);
    cin >> n;
    rep(i, n) {
        int u, k;
        cin >> u >> k;
        rep(i, k) {
            int v, c;
            cin >> v >> c;
            l[u][v] = c;
        }
    }
    dijkstra(0);
    rep(i, n) cout << i << ' ' << d[i] << endl;
}

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

using namespace std;

#define INF (10000001)

typedef pair<int, int> Edge;

int main()
{
    priority_queue<Edge,vector<Edge>,greater<Edge> > pq;
    vector<vector<Edge> > e;
    vector<int> d;
    Edge etemp;
    int n,u,k,v,c;
    cin >> n;
    e.resize(n);
    d.resize(n);
    for(int i=0; i<n; ++i) {
        cin >> u >> k;
        for(int j=0; j<k; ++j) {
            cin >> v >> c;
            e[u].push_back(Edge{c,v});
        }
        d[u]=INF;
    }

    d[0]=0;
    for(auto x : e[0]) {
        pq.push(x);
    }
    while(!pq.empty()) {
        etemp=pq.top(); pq.pop();
        v=etemp.second;
        c=etemp.first;
        if(d[v]<c) continue;
        d[v]=c;
        for(auto x : e[v]) {
            if(d[x.second]<=c+x.first) continue;
            pq.push(Edge{c+x.first,x.second});
        }
    }
    for(int i=0; i<n; ++i) {
        cout << i << " " << d[i] << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int MAX_N = 110;
int cost[MAX_N][MAX_N], d[MAX_N];
bool used[MAX_N];
void dijkstra(int n)
{
    for(int i = 0; i <= n; i++) { d[i] = INF; used[i] = false; }
    d[0] = 0;
    while(true)
    {
        int v = -1;
        for(int u = 0; u < n; u++)
        {
            if(not used[u] && (v == -1 || d[u] < d[v])) v = u;
        }
        if(v == -1) break;
        used[v] = true;
        for(int u = 0; u < n; u++) d[u] = min(d[u], d[v] + cost[v][u]);
    }
    for(int i = 0; i < n; i++) cout << i << " " << d[i] << endl;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++) cost[i][j] = INF;
    }
    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;
            cost[u][v] = c;
        }
    }
    dijkstra(n);
    return 0;
}