Go: package main

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

const BIG_COST = 200000

const (
	ST_NOT_YET = iota
	ST_JOINED
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	nNodes := scanInt(sc)

	costs := make([][]int, nNodes)
	graph := make([][]int, nNodes)

	states := make([]int, nNodes)
	costSums := make([]int, nNodes)

	for i := 0; i < nNodes; i++ {
		costs[i] = make([]int, nNodes)
		costSums[i] = BIG_COST
	}

	for i := 0; i < nNodes; i++ {
		u := scanInt(sc)
		k := scanInt(sc)
		graph[u] = make([]int, k)
		for d := 0; d < k; d++ {
			v := scanInt(sc)
			graph[u][d] = v
			costs[u][v] = scanInt(sc)
		}
	}

	costSums[0] = 0
	for {
		minCost := BIG_COST
		var u int

		for i, cost := range costSums {
			if states[i] != ST_JOINED && cost < minCost {
				minCost = cost
				u = i
			}
		}

		if minCost == BIG_COST {
			break
		}

		states[u] = ST_JOINED

		for _, v := range graph[u] {
			cost := minCost + costs[u][v]
			if cost < costSums[v] {
				costSums[v] = cost
			}
		}
	}

	w := bufio.NewWriter(os.Stdout)
	for i, cost := range costSums {
		fmt.Fprintf(w, "%d %d\n", i, cost)
	}
	w.Flush()
}

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

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

#define INF 1000000

int n;
int cost[110][110], d[110];
bool used[110];

void dijkstra(int s){

  //initialization
  for(int i = 0;i < n;i++) d[i] = INF;
  for(int i = 0;i < n;i++) used[i] = false;

  //distance of starting position is 0
  d[s] = 0;
  
  while(true){
    int v = -1;
    
    for(int u = 0;u < n;u++){
      if(!used[u] && (v == -1 || d[u] < d[v])) v = u;
    }
    
    if(v == -1) break; //finish
    used[v] = true; //use v

    //update distance
    for(int u = 0;u < n;u++){
      d[u] = min(d[u], d[v] + cost[v][u]);
    }
  }
}

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

  //input and initialization
  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++){
    cin >> u >> k;
    for(int j = 0;j < k;j++){
      cin >> v >> c;
      cost[u][v] = min(cost[u][v], c);
    }
  }
  
  dijkstra(0);

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

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 (true) {
    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] != 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, 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 MAX 100

int n;
long d[MAX], C[MAX][MAX];
vector<int> M[MAX];

struct Edge{
    int u;
    Edge(int u): u(u){}
    bool operator < (const Edge &e) const {
        if(d[u] != d[e.u]) return d[u] < d[e.u];
        else return u < e.u;
    }
};

void dijkstra(){
    bool seen[n], todo[n];
    list<Edge> E;
    fill(seen, seen + n, false);
    fill(todo, todo + n, false);
    seen[0] = true;
    E.push_front(Edge(0));
    
    while(!E.empty()){
        E.sort();
        int u = E.begin()->u;
        seen[u] = true;
        E.pop_front();
        vector<int>::iterator it;
        
        for(it = M[u].begin(); it != M[u].end(); it++){
            int v = *it;
            if(!seen[v]) d[v] = min(d[v], d[u] + C[u][v]);
            if(!seen[v] && !todo[v]){
                E.push_back(Edge(v));
                todo[v] = true;
            }
        }
    }
    return;
}

int main(){
    cin >> n;
    fill(d, d + n, LONG_MAX);
    d[0] = 0;
    for(int i = 0; i < n; i++){
        fill(C[i], C[i] + n, LONG_MAX);
        int u, q, v, cost;
        cin >> u >> q;
        for(int j = 0; j < q; j++){
            cin >> v >> cost;
            C[u][v] = cost;
            M[u].push_back(v);
        }
    }
    dijkstra();
    for(int i = 0; i < n; i++)
        cout << i << " " << d[i] << endl;
    return 0;
}

C++: #include<iostream>
#define INF 1e9
using namespace std;

int n,mp[101][101],D[101];
void dijkstra(){
  bool used[101]={};
  for(int i=0;i<101;i++)D[i]=INF;
  D[0]=0;
 
  while(1){
    int cost=INF,pos=-1;
    for(int i=0;i<n;i++) if(!used[i]&&D[i]<cost) pos=i,cost=D[i];//もし使用していなくて格納されているものよりコストが大きれればpositionをずらし、コストに今入っているDを入れる
    if(pos==-1)return ;
    used[pos]=1;//positionをずらしたら見たことになるので１に書き換える    
    for(int i=0;i<n;i++)D[i]=min(D[i],cost+mp[pos][i]);
  }
}

int main(){
     cin>>n;
  for(int i=0;i<101;i++)
    for(int j=0;j<101;j++) mp[i][j]=INF;
   
  for(int i=0,a,m;i<n;i++){
    cin>>a>>m;//aが頂点mが次数
    for(int j=0,b,c;j<m;j++)cin>>b>>c,mp[a][b]=c;
  }
  dijkstra();
  for(int i=0;i<n;i++)cout <<i<<" "<<D[i]<<endl;
   
  return 0;
}

C++: #include<iostream>
using namespace std;
#define INF 100000
int m[100][100]; //adjacency matrix
int n; //vertexes
void dijkstra();
int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            m[i][j] = INF;
        }
    }
    for (int i = 0; i < n; i++) {
        int u; //number
        int k; //output orders
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int v; //vertex
            int c; //weight
            cin >> v >> c;
            m[u][v] = c;
        }
    }
    dijkstra();
    return 0;
}
void dijkstra() {
    int d[100]; //minimum cost
    int p[100]; //top parent
    d[0] = 0;
    p[0] = 1;
    for (int i = 1; i < n; i++) {
        p[i] = 0;
        d[i] = INF;
    }
    while (1) {
        int minv = INF;
        int u = -1;
        for (int i = 0; i < n; i++) {
            if (minv > d[i] && p[i] != 2) { //firstly only d[0]
                u = i; //tmp parent
                minv = d[i]; //min cost of 0 to i
            }
        }
        if (u == -1) {
            break;
        }
        p[u] = 2; //決まったら
        for (int v = 0; v < n; v++) {
            if (m[u][v] != INF && p[v] != 2) { //u and v are connected
                if (d[v] > d[u] + m[u][v]) {
                    d[v] = d[u] + m[u][v]; //get smaller cost
                    //ここでd[v]がINFから解放され、次の親になれる
                    p[v] = 1;
                }
            }
        }
    }
    for (int i = 0; i < n; i++) {
        cout << i << " ";
        if (d[i] == INF) {
            cout << -1 << endl;
        } else {
            cout << d[i] << endl;
        }
    }
}