Go: package main

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

const (
	white int = iota
	gray
	black
)

type node struct {
	id     int
	parent int
	edge   []int
	weight []int
	color  int
}

type graph struct {
	nodes    []node
	distance []int
}

var infty = 1 << 32
var null = -1

func constructgraph() *graph {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)

	g := &graph{make([]node, n), make([]int, n)}

	for i := 0; i < n; i++ {
		id := nextInt(sc)
		edges := nextInt(sc)
		n := node{}
		n.id = id
		n.edge = make([]int, edges)
		n.weight = make([]int, edges)
		n.color = white
		for j := 0; j < edges; j++ {
			to := nextInt(sc)
			w := nextInt(sc)
			n.edge[j] = to
			n.weight[j] = w
		}
		g.nodes[id] = n
	}
	return g
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func (g *graph) preparedijkstra(s int) {
	for i := 0; i < len(g.nodes); i++ {
		g.nodes[i].color = white
		g.nodes[i].parent = null
		g.distance[i] = infty
	}
	g.distance[s] = 0
}

func (g *graph) dijkstra(s int) []int {
	g.preparedijkstra(s)

	for {
		var u int
		mincost := infty
		for i, d := range g.distance {
			if g.nodes[i].color != black && mincost > d {
				mincost = d
				u = i
			}
		}

		if mincost == infty {
			break
		}

		g.nodes[u].color = black

		for i, e := range g.nodes[u].edge {
			if g.nodes[e].color != black {
				if g.distance[e] > g.distance[u]+g.nodes[u].weight[i] {
					g.distance[e] = g.distance[u] + g.nodes[u].weight[i]
					g.nodes[e].parent = u
					g.nodes[e].color = gray
				}
			}
		}
	}
	return g.distance
}

func printShortestPath(d []int) {
	for i, v := range d {
		fmt.Printf("%d %d\n", i, v)
	}
}

func main() {
	g := constructgraph()
	d := g.dijkstra(0)
	printShortestPath(d)
}

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

static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;


int n, M[MAX][MAX];

void dijkstra() {
    int minv;
    int d[MAX], 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 (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 (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, 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>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];
int d[MAX];

void dijkstra(int s) {
    int p[n];
    int color[n];
    
    for(int i=0; i<n; i++) {
        color[i] = WHITE;
        d[i] = INFTY;
        p[i] = -1;
    }
    
    d[s] = 0;
    
    while(1) {
        int u;
        int mincost = INFTY;
        for (int i=0; i<n; i++) {
            if (color[i] != BLACK && d[i] < mincost) {
                mincost = d[i];
                u = i;
            }
        }
        
        if (mincost == INFTY) break;
        
        color[u] = BLACK;
        
        for (int v=0; v<=n; v++) {
            if (color[v] != BLACK && M[u][v] != INFTY) {
                if(d[u] + M[u][v] < d[v]) {
                    d[v] = d[u] + M[u][v];
                    p[v] = u;
                    color[v] = GRAY;
                }
            }
        }
    }
}

int main() {
    scanf("%d", &n);
    for (int i=0; i<n; i++) {
        for (int j=0; j<n; j++) {
            int tmp;
            scanf("%d", &tmp);
            M[i][j] = (tmp == -1) ? INFTY : tmp;
        }
    }
    
    dijkstra(0);
    
    for(int i=0; i<n; i++) {
        printf("%d %d\n", i, d[i]);
    }
    
    return 0;
}

C++: #include <iostream>
#include <cstring>
#define MAX 120000
using namespace std;

int matrix[105][105],n,closest[105],close[105];

void djst(){
    int i,j,k;
    for(i=1;i<n;i++){
        if(matrix[0][i]!=-1)close[i]=matrix[0][i];
    }
    while(1){
        int mi=MAX,rec=-1;
        for(i=1;i<n;i++){
            if(close[i]!=-1&&close[i]<mi&&closest[i]==-1){
                mi=close[i];
                rec=i;
            }
        }
        if(rec==-1)break;
        closest[rec]=mi;
        close[rec]=MAX;
        for(j=1;j<n;j++){
            if(closest[j]==-1&&matrix[rec][j]!=-1){
                if(mi+matrix[rec][j]<close[j]||close[j]==-1)close[j]=mi+matrix[rec][j];
            }
        }
    }
}
int main(){
    memset(close,-1,sizeof(close));//memset??????????????¨0???-1???????????°???????§????
    memset(closest,-1,sizeof(closest));
    memset(matrix,-1,sizeof(matrix));
    int i,j;
    cin>>n;
    for(i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        for(j=0;j<b;j++){
            int c,d;
            cin>>c>>d;
            matrix[a][c]=d;
        }
    }
    closest[0]=0;
    djst();
    for(i=0;i<n;i++){
        cout<<i<<" "<<closest[i]<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <algorithm>
#define N 100
#define INF (1<<30)
using namespace std;

int n, M[N][N], d[N], color[N] = {0};

void Dijk(int s) {
	int min;
	for (int i = 0;i < n;i++) d[i] = INF;
	d[s] = 0;
	while (true) {
		int u=-1;
	    min = INF;
		for (int i = 0;i < n;i++) {
			if (color[i] == 0 && d[i] < min)
				min = d[i];
			    u = i;
		}

		if (u==-1) break;

		color[u] = 1;

		for (int v = 0;v < n;v++) {
			if (color[v] == 0 && M[u][v] != INF)
				if (d[v] > d[u] + M[u][v]) {
					d[v] = d[u] + M[u][v];
				}
		}
	}

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

}

int main() {

	for (int i = 0;i < N;i++)
		for (int j = 0;j < N;j++) M[i][j] = INF;

	cin >> n;
	for (int i = 0;i < n;i++) {
		int u,v;
		cin >> u;
		int k;
		cin >> k;
		for (int j = 0;j < k;j++) {
			cin >> v;
			cin >> M[u][v];
		}
	}

	Dijk(0);

}

C++: #include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll inf=99999999999999999;
#define rep(i,t,n) for(int i=t;i<n;i++)
const int maxn=1e2+7;
ll d[maxn][maxn];
int main(){
    int a,n,m,x;ll z;
    scanf("%d",&n);
    rep(i,0,n) rep(j,0,n) d[i][j]=inf;
    rep(i,0,n) d[i][i]=0;
    rep(i,0,n){
        scanf("%d%d",&a,&m);
        rep(j,0,m){
            scanf("%d%lld",&x,&z);
            d[a][x]=min(d[a][x],z);
        }
    }
    if(n==1){
        printf("0 0\n");
        return 0;
    }
    rep(k,0,n) rep(i,0,n) rep(j,0,n) d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
    rep(i,0,n) printf("%d %lld\n",i,d[0][i]);
    return 0;
}