Go: package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

const (
	INFTY = 1 << 21
	NIL   = -1
)

const (
	WHITE = iota
	GRAY
	BLACK
)

type Graph [][]int

func (g *Graph) dikstra(n int) string {
	var (
		u, minv = 0, 0
	)

	d := make([]int, n)
	color := make([]int, n)

	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 && (*g)[u][v] != INFTY {
				if d[v] > d[u]+(*g)[u][v] {
					d[v] = d[u] + (*g)[u][v]
					color[v] = GRAY
				}
			}
		}
	}

	var out bytes.Buffer
	for i := 0; i < n; i++ {
		out.WriteString(fmt.Sprintf("%d ", i))
		if d[i] == INFTY {
			out.WriteString(fmt.Sprintf("%d\n", -1))
			continue
		}
		out.WriteString(fmt.Sprintf("%d\n", d[i]))
	}

	return strings.TrimRight(out.String(), "\n")
}

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	g := make(Graph, n)
	for i := 0; i < n; i++ {
		g[i] = make([]int, n)
		for j := 0; j < n; j++ {
			g[i][j] = INFTY
		}
	}

	for i := 0; i < n; i++ {
		sc.Scan()
		u, _ := 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())

			g[u][v] = c
		}
	}

	return g.dikstra(n)
}

func main() {
	fmt.Println(answer(os.Stdin))
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#define INF 1<<20
using namespace std;
typedef unsigned long long ull;
int n;
int A[1000][1000];
bool used[1000];
ull 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++){
    cout << i << " " << D[0][i] << endl;
  }
 
  return 0;
}

C++: #include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>

using namespace std;

typedef pair<int,int>pii;
#define INF 0x3f3f3f3f
#define fi first
#define se second

int mcos[105];
vector <pii> G[105];
int N;


void dijkstra(int start){
  priority_queue<pii,vector<pii>,greater<pii> > pq;

  pq.push( pii(0,start) );
  memset( mcos,INF,sizeof(mcos));
  mcos[start]=0;

  
  while(!pq.empty() ){
    const pii tmp=pq.top();
    pq.pop();
    
    const int now=tmp.se;
    
    if(mcos[now] < tmp.fi) continue;
    
    for(int i=0;i<G[now].size();++i){
      const int newcost = G[now][i].fi + tmp.fi;
      const int next= G[now][i].se;
      
      if(newcost < mcos[next] ){
	mcos[next]=newcost;
	pq.push( pii(newcost,next) );
      }
    }
  }
  return ;
  
}

int main (){
  cin>>N;
  int k,u,v,c;

  for(int i=0;i<N;i++){
    cin>>u>>k;
    for(int j=0;j<k;j++){
      cin>>v>>c;
      G[u].push_back(make_pair(c,v));
    }
  }
  dijkstra(0);
  for(int i=0;i<N;i++){
    cout<<i<<" "<<mcos[i]<<endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>

std::vector<int> color;
std::vector<std::vector<int>> M;
std::vector<int> d;
std::vector<int> p;
int INF = 1001001001;
int sum = 0;

void dijkstra(int n){
    for(int i = 0; i < n; i++){
        color[i] = 0;
        d[i] = INF;
    }

    d[0] = 0;
    p[0] = -1;

    while(true){
        int u;
        int mincost = INF;
        for(int i = 0; i < n; i++){
            if(color[i] != 1 && d[i] < mincost){
                mincost = d[i];
                u = i;
            }
        }

        if(mincost == INF){
            break;
        }

        color[u] = 1;

        for(int i = 0; i < n; i++){
            if(color[i] != 1 && M[u][i] != -1){
                if(d[u] + M[u][i] < d[i]){
                    d[i] = d[u] + M[u][i];
                }
            }
        }

    }
    
    for(int i = 0; i < d.size(); i++){
        sum += d[i];
    }

}

int main(void){
    int n;
    std::cin >> n;

    color.resize(n);

    M.resize(n, std::vector<int>(n));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            M[i][j] = INF;
        }
    }

    d.resize(n);
    p.resize(n);

    int u, k, v;

    for(int i = 0; i < n; i++){
        std::cin >> u >> k;
        for(int i = 0; i < k; i++){
            std::cin >> v;
            std::cin >> M[u][v];
        }
    }
    
    
    dijkstra(n);
    
    for(int i = 0; i < n; i++){
        std::cout << i << " " << d[i] << std::endl;
    }

    return 0;
}

C++: #include <iostream>

using namespace std;

#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INFTY 99999999

int color[MAX];
int M[MAX][MAX];
int d[MAX];
int p[MAX];
int n;

int dijkstra(int s)
{

	int mincost;
	int u;

	for (int i = 0; i < n; i++) {
		d[i] = INFTY;
		p[i] = -1;
	}
	d[s] = 0;

	while (true) {
		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 i = 0; i < n; i++) {
			if (color[i] != BLACK&&M[u][i] != -1) {
				if (d[u] + M[u][i] < d[i]) {
					d[i] = d[u] + M[u][i];
					p[i] = u;
					color[i] = GRAY;
				}
			}
		}


	}


	int sum = 0;

	for (int i = 0; i < n; i++) {
		sum += d[i];
	}

	return sum;


}

int main(void)
{

	cin >> n;

	int u;
	int k;
	int v;

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

	for (int i = 0; i < n; i++) {
		cout << i << " " << dijkstra(i) << endl;
	}

	return 0;
}

C++: #include <iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1<<21);

enum Color {
  WHITE, GRAY, BLACK
};

int M[MAX][MAX];
int d[MAX];
int p[MAX];
Color color[MAX];
int n;

void init() {
  for (int i = 0; i < n; i++) {
    color[i] = WHITE;
    d[i] = INFTY;
  }
}

void dijkstra(int s) {
  init();
  d[s] = 0;
  p[s] = -1;

  while (true) {
    int mincost = INFTY;
    int u;
    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 (M[u][v] != INFTY && color[v] != BLACK) {
        if (d[u] + M[u][v] < d[v]) {
          d[v] = d[u] + M[u][v];
          p[v] = u;
          color[v] = GRAY;
        }
      }
    }
  }
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      M[i][j] = INFTY;
    }
  }
  for (int i = 0; i < n; i++) {
    int elem, index, v;
    cin >> v >> elem;
    for (int j = 0; j < elem; j++) {
      int u;
      cin >> u;
      cin >> M[v][u];
    }
  }
  dijkstra(0);
  for (int i = 0; i < n; i++) {
    cout << i << " " << d[i] << endl;
  }
  return 0;
}