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>
using namespace std;
#define MAX 101
#define INFTY (1<<21)
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[MAX][MAX];
void dijkstra()
{
    int minv;
    int d[MAX], color[MAX], p[MAX];
    for(int i=0; i<MAX; i++)
    {
        color[i] = WHITE;
        d[i] = INFTY;
        p[i] = -1;
    }
    d[0] = 0;
    color[0] = GRAY;
    while(1)
    {
        minv = INFTY;
        int u = -1;
        for(int 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(int v=0; v<n; v++)
        {
            if(color[v] != BLACK && M[u][v] != -1)
            {
                if(d[u]+M[u][v] < d[v])
                {
                    d[v] = d[u] + M[u][v];
                    p[v] = u;
                    color[v] = GRAY;
                }
            }
        }
    }
    for(int i=0; i<n; i++)
    {
        cout << i << " " << d[i] << endl;
    }
}
int main()
{
    cin >> n;
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
            M[i][j] = INFTY;
    }
    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 <stdio.h>
#define INF (1<<21)

int main(void)
{
 int i,j,n,m,u,k,l,v,c,a[10000],b[10000],d[10000][10000];

 scand("%d",&n);
 
 for(i=0;i<n;i++){
 	scanf("%d %d",&u,&k);
 	a[i]=INF;
 	b[i]=0;
 	for(j=0;j<k;j++){
 		scanf("%d %d",&v,&c);
 		d[u][v]=c;
 	}
 }
 a[0]=0;
 
 while(1){
 	
 	l=-1;
 	m=INF;
 	
 	for(i=0;i<n;i++){
 		if(a[i]<m && b[i]=0){
 			m=a[i];
 			l=i;
 		}
 	}
 	
 	if(l==-1) break;
 	
 	b[l]=1;
 	
 	for(i=0;i<n;i++){
 		if(a[i]>=d[l][i]+a[l]) a[i]=d[l][i]+a[l];
 	}
 }
 
 for(i=0;i<n;i++){
 	if(a[i]==INF) printf("%d -1\n",i);
 	else printf("%d %d\n",i,a[i]);
 }
 
 return 0;
}

 return 0;
}

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

struct Edge {
    int from, to, cost;
    Edge(int f, int t, int c) : from(f), to(t), cost(c) { }
    bool operator <(const Edge& e) const {
        return cost < e.cost;
    }
};

const int INF = (int)1e9;
typedef pair<int, int> P;

vector<int> dijkstra(const vector<vector<Edge> >& g, int s) {
    vector<int> res(g.size(), INF);
    priority_queue<P, vector<P>, greater<P> > Q;
    Q.push(P(0, s));
    res[s] = 0;
    while(!Q.empty()) {
        P p = Q.top(); Q.pop();
        if(p.first > res[p.second]) continue;
        for(int i = 0; i < (int)g[p.second].size(); i++) {
            Edge e = g[p.second][i];
            if(res[e.to] > p.first + e.cost) {
                res[e.to] = p.first + e.cost;
                Q.push(P(res[e.to], e.to));
            }
        }
    }
    return res;
}

int main() {
    int N; cin >> N;
    vector<vector<Edge> > es(N);
    for(int i = 0; i < N; i++) {
        int u, k; cin >> u >> k;
        while(k--) {
            int v, c; cin >> v >> c;
            es[u].push_back(Edge(u, v, c));
        }
    }
    vector<int> res = dijkstra(es, 0);
    for(int i = 0; i < N; i++) {
        cout << i << ' ' << res[i] << endl;
    }
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#define INF 1<<20
using namespace std;
int n;
int A[1000][1000];
int d[1000];
bool used[1000];
int D[1000][1000];

void Init(int f){
  for(int i=0;i<f;i++){
    for(int j=0;j<f;j++)D[i][j] = INF;
  }

}

int main(){
  scanf("%d",&n);
  int u,k,C,V;
  Init(n);
 
  for(int i=0;i<n;i++){
      scanf("%d %d",&u,&k);     
      for(int j=0;j<k;j++){
	scanf("%d %d",&V,&C);
	D[u][V] = C;
	D[V][u] = C;
      }     
  }
  
  for(int i=0;i<n;i++)D[i][i] = 0;
  for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++)D[i][j] = min(D[i][j],D[i][k] + D[k][j]); 
  for(int i=0;i<n;i++){
    printf("%d %d\n",i,D[0][i]);
  }

  return 0;
}

C++: #include <iostream>
#include <stack>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstring>
#include <string.h>
#include <cstdio>
#include <numeric>
#include <string.h>
#include <set>
#include <map>
#define ll long long
using namespace std;
#define mem(a) memset(a,0,sizeof(a))
#define mec(b,a) memcpy(b,a,sizeof(a))

const ll inf = 0x3f3f3f3f;
const int maxn = 1000;

int data[maxn][maxn];
int n;

void dijkstra(){
	int i,j,min,v;
	int d[maxn];
	bool vis[maxn];
 
	for(i=0;i<n;i++){
		vis[i]=0;
		d[i]=data[0][i];
	}
 
	for(i=0;i<n;i++){
		min=inf;
		for(j=0;j<n;j++)
			if(!vis[j] && d[j]<min){
				v=j;
				min=d[j];
			}
		vis[v]=1;
 
		for(j=0;j<n;j++)
			if(!vis[j] && d[j]>data[v][j]+d[v])
				d[j]=data[v][j]+d[v];
	}
	for(int i=0; i<n; i++){
		cout<<i<<" "<<d[i]<<endl;
	}
}

int main(){
	cin>>n;
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			if(i==j){
				data[i][j] = 0;
			}else{
				data[i][j] = data[j][i] = inf;
			}
		}
	}
	for(int i=0; i<n; i++){
		int start,m;
		cin>>start>>m;
		for(int j=0; j<m; j++){
			int end,weight;
			cin>>end>>weight;
			data[start][end] = data[end][start] = min(data[start][end],weight);
		}
	}
	
	dijkstra();
	 
	
    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
static const int MAX = 10000;
static const int INFTY = (1<<20);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;
//???????????????????????\??¨??¨??????
vector<pair<int, int>>adj[MAX];

void dijkstra(){
    priority_queue<pair<int, int>>PQ;
    int color[MAX];
    int d[MAX];
    for(int i = 0; i<n; i++){
        d[i] = INFTY;
        color[i] = WHITE;
    }

    d[0] = 0;
    PQ.push(make_pair(0,0));
    color[0] = GRAY;

    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[v]>d[u]+adj[u][j].second){
                d[v]=d[u]+adj[u][j].second;
                //priority_queue ?????????????????§??????????????????-1
                PQ.push(make_pair(d[v]*(-1),v));
                color[v]=GRAY;
            }
        }
    }

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

int main(){
    int k,u,v,c;

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

    dijkstra();
}