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 <stdio.h>
static const int MAX=100;
static const int INFTY=(1<<30);
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;
int n,M[MAX][MAX];

void dijkstra(){
    int minv,i,o;
    int d[MAX],color[MAX];
    for(i=0;i<n;i++){
        d[i]=INFTY;
        color[i]=WHITE;
    }
    d[0]=0;
    color[0]=GRAY;
    while(1){
        minv=INFTY;
        int 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(o=0;o<n;o++){
            if(color[o]!= BLACK && M[u][o] != INFTY){
                if(d[o]>d[u]+M[u][o]){
                    d[o]=d[u]+M[u][o];
                    color[o]=GRAY;
                }
            }
        }
    }
    for(i=0;i<n;i++)
        printf("%d %d\n",i,(d[i]==INFTY)?-1:d[i]);
}

int main(void){
    int i,o,k,c,u,v;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        for(o=0;o<n;o++)
            M[i][o]=INFTY;
    for(i=0;i<n;i++){
        scanf("%d %d",&u,&k);
        for(o=0;o<k;o++){
            scanf("%d %d",&v,&c);
            M[u][v]=c;
        }
    }
    dijkstra();
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <queue>
const int inf=1e9;
using namespace std;
int main(){

  int n,now=0;
  priority_queue < pair<int,int>, vector<pair<int,int> >, greater<pair<int,int> > > g[100000];
  cin>>n;
  for(int i=0,u,k,v,c;i<n&&cin>>u>>k;i++) for(int j=0;j<k&&cin>>v>>c;j++) g[u].push(make_pair(c,v));
  int flag[100]={},c[100]={};
  for(int i=1;i<n;i++) c[i]=inf;
  for(int i=0;i<n-1;i++){
    int next=g[now].top().second;
    for(;!g[now].empty();g[now].pop()) if(!flag[g[now].top().second]) c[g[now].top().second]=min(c[g[now].top().second],c[now]+g[now].top().first);
    flag[now]=1;
    now=next;
  }
  for(int i=0;i<n;i++) cout<<i<<" "<<c[i]<<endl;
  return 0;

}

C++: #include <iostream>
 using namespace std;
 static const int WHITE = 0;
 static const int GRAY = 1;
 static const int BLACK =2;
 static const int MAX = 100;
 static const int INFTY = (1<<21);
 
 int n,M[MAX][MAX];
 
 void dijks(){
 	int minv;
 	int d[MAX];
 	int color[MAX];
 	for(int i=0;i<n;i++){
 		d[i] = INFTY;
 		color[i] = WHITE;
 	}
 	
 	d[0] = 0;
 	color[0] = GRAY;
 	while(1){
 		minv = INFTY;
 		int u=-1;
 		for(int i=0;i<n;i++){
 			if(color[i]!=BLACK&&d[i]<minv){
 				minv = d[i];
 				u=i;
 			}
 		}
 		
 		if(u==-1) break;
 		
 		color[u] = BLACK;
 		
 		for(int 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(int i=0;i<n;i++){
 		cout<<i<<" "<<(d[i]==INFTY?-1: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,u,c,v;
 	for(int i=0;i<n;i++){
 		cin>>u>>k;
 		for(int j=0;j<k;j++){
 			cin>>c>>v;
 			M[u][c] = v;
 		}
 	}
 	dijks();
 	return 0;
 }