Go: package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

const NIL = -1

type Node struct {
	id     int
	weight int
}

func init() {
	sc.Split(bufio.ScanWords)
}

type NodeHeap []Node

func (h NodeHeap) Len() int           { return len(h) }
func (h NodeHeap) Less(i, j int) bool { return h[i].weight < h[j].weight }
func (h NodeHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *NodeHeap) Push(x interface{}) {
	*h = append(*h, x.(Node))
}

func (h *NodeHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()

	list := make([][]int, n)
	weight := make([]int, n)
	for i := range list {
		list[i] = make([]int, n)
		weight[i] = NIL
		for j := range list[i] {
			list[i][j] = NIL
		}
	}

	for i := 0; i < n; i++ {
		u := scanInt()
		k := scanInt()
		for j := 0; j < k; j++ {
			v := scanInt()
			w := scanInt()
			list[u][v] = w
		}
	}

	start := Node{id: 0, weight: 0}
	h := &NodeHeap{start}
	heap.Init(h)

	for h.Len() > 0 {
		node := heap.Pop(h).(Node)
		if weight[node.id] != NIL {
			continue
		}
		weight[node.id] = node.weight

		for i, w := range list[node.id] {
			if w == NIL {
				continue
			}
			heap.Push(h, Node{id: i, weight: w + node.weight})
		}
	}

	w := bufio.NewWriter(os.Stdout)
	for i := 0; i < n; i++ {
		fmt.Fprint(w, i)
		fmt.Fprint(w, " ")
		fmt.Fprint(w, weight[i])
		fmt.Fprintln(w)
	}
	w.Flush()
}

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,A[MAX][MAX];

void ant();

int main(){
  cin >> n;

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      A[i][j]=INFTY;
    }
  }

  int a,b,c,d;

  for(int i=0;i<n;i++){
    cin >> a >> b;
    for(int j=0;j<b;j++){
      cin >> c >> d;
      A[a][c]= d;
    }
  }
  ant();
  return 0;
}

void ant(){
  int minv,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 j=0;j<n;j++){
      if(minv > d[j] && color[j]!=BLACK){
        u=j;
        minv=d[j];
      }
    }
    if(u==-1)break;

    color[u]=BLACK;

    for(int m=0;m<n;m++){
      if(color[m]!=BLACK && A[u][m]!=INFTY){
        if(d[m]>d[u]+A[u][m]){
          d[m]=d[u]+A[u][m];
          color[m]=GRAY;
        }
      }
    }
  }
  for(int i=0;i<n;i++){
    cout << i << " " << (d[i]==INFTY ? -1 : d[i]) << endl;
  }
}

C++: #include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;
#define MAX 10000000

int b[110];
bool used[110];
struct edge{int from, to, cost;};

int solve(int a[110][110], int n){
	b[0] = 0;
	//used[0] = true;
	while(1){
		int v = -1;
		for(int i = 0;i < n;i++){
			if(!used[i] && (v == -1 || b[v] > b[i]))v = i;
		}
		if(v == -1)break;
		used[v] = true;
		for(int i = 0;i < n;i++){
			if(a[v][i] != -1)b[i] = min(b[i], b[v] + a[v][i]);
		}
	}
	return 0;
}

int main(){
	int a[110][110], n;
	fill((int*)a, (int*)(a+110), -1);
	fill(b, b+110, MAX);
	fill(used, used, false);
	cin >> n;
	for(int i = 0;i < n;i++){
		int u, k, c, d;
		cin >> u >> k;
		for(int j = 0;j < k;j++){
			cin >> c >> d;
			a[u][c] = d;
		}
	}
	
	solve(a, n);
	for(int i = 0;i < n;i++){
		cout << i << " " << b[i] << endl;
	}
	
	return 0;
}
/*
5
0 3 2 3 3 1 1 2
1 2 0 2 3 4
2 3 0 3 3 1 4 1
3 4 2 1 0 1 1 4 4 3
4 2 2 1 3 3
*/

C++: #include <stdio.h>
#define N 101
#define INF 0xffffff
#define NIL 0

typedef enum {
  WHITE,
  BLACK,
} color_t;


int main(){
  int n, i, j, u ,k;
  int w[N][N]= {0}; // 0-origin w[u][v] : the weight of "node u -> node v"
  int adj[N][N];  // adj[u][i] : the adjency nodes of node u
  int v;
  int d[N], pi[N];
  color_t color[N];
  int mincost;
  int sum=0;

  for( i = 0 ; i < N ; i++){
    for( j = 0 ; j < N ; j++){
      w[i][j] = INF;
      adj[i][j] = INF;
    }
  }

  scanf("%d", &n);
  for ( i = 0; i < n; i++ ){
  scanf("%d", &u);
  scanf("%d", &k);
    for( j = 0 ; j < k ; j++){
      scanf("%d", &v);      
      scanf("%d", &w[u][v] );
      adj[u][j] = v;
    }
  }

  // initialize single source
  for( i = 0 ; i < N ; i++){
    d[i] = INF;
    pi[i]= NIL;
  }
  const int s = 0;
  d[s] = 0; // s: source
 
  // dijkstra()
  while(1){
    mincost = INF;
    for(i = 0 ; i < n ; i++){
      if( color[i] != BLACK && d[i] < mincost ){
	mincost = d[i];
	u = i;
      }
    }

    if(mincost == INF){
      break;
    }
    
    color[u] = BLACK; 
    for( i=0 ; i < n ; i++){
      v = adj[u][i];
      if( v == INF ){
	break;
      }
      if( color[v] != BLACK && (d[u] + w[u][v]) < d[v] ){
	pi[v] = u;
	d[v]  = d[u] + w[u][v];
      }
    }
    
  }

  // print
  sum = 0;
  for( i = 0 ; i < n ; i++ ){
    if( d[i] != INF ){
      printf("%d %d\n" ,i ,d[i]);
    }
  }

  return 0; // Don't forget return 0
}

C++: #include <bits/stdc++.h>
using namespace std;

const int MAX=105;
int state[MAX],N,D[MAX];
vector<pair<int,int>> S[MAX];
priority_queue<pair<int,int>> Q;

void dijkstra(){
    int cnt=1;
    for(int i=0;i<N;i++){
        state[i]=0;
        D[i]=100000000;
    }
    state[0]=1;
    D[0]=0;
    for(int i=0;i<S[0].size();i++){
        Q.push(make_pair(-S[0][i].second,S[0][i].first));
        D[S[0][i].first]=min(D[S[0][i].first],D[0]+S[0][i].second);
    }
    while(1){
        int a=Q.top().second;
        cout<<a<<endl;
        if(state[a]==0){
            Q.pop();
            state[a]=1;
            cnt++;
            for(int i=0;i<S[a].size();i++){
                if(state[S[a][i].first]==0){
                    Q.push(make_pair(-S[a][i].second,S[a][i].first));
                    D[S[a][i].first]=min(D[S[a][i].first],D[a]+S[a][i].second);
                }
            }
        }
        else Q.pop();
        if(cnt==N) break;
    }
    return;
}


int main(){
    
    cin>>N;
    for(int i=0;i<N;i++){
        int l,a;cin>>l>>a;
        for(int j=0;j<a;j++){
            int b,c;cin>>b>>c;
            S[i].push_back(make_pair(b,c));
        }
    }
    dijkstra();
    for(int i=0;i<N;i++){
        cout<<i<<" "<<D[i]<<endl;
    }
}

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

int A[100][100];
char type[100];
int d[100];//経路の長さ<-初期値15000
int n;

int Dijkstra(int k){
    type[k] = 'B';
    int min = 0;
    for(int i=1; i<n; i++){
        if((A[k][i] != -1) && (type[i] != 'B')){
            type[i] = 'G';
            //長さを調査、短ければ更新
            if(d[k] + A[k][i] < d[i]){
                d[i] = d[k] + A[k][i];
            }
        }
    }
    int FLAG = 0;
    for(int j=1; j<n; j++){
        if(type[j] == 'G'){
            if(FLAG == 0){
                min = j;
            } else {
                if(d[j] < d[min]){
                min = j;
                }
            }
            FLAG = 1;
        }
    }
    if(min == 0){
        return 0;
    } else {
        Dijkstra(min);
    }
}

int main(){
    cin >> n;
    for(int i=0; i<n; i++){//Aを-1に初期化,dを最大値に初期化
        d[i] = 100000000;
        type[i] = 'W';
        for(int j=0; j<n; j++){
            A[i][j] = -1;
        }
    }
    //↓↓↓ここで、入力を表の形に代入
    int p, q, r, s;
    for(int i=0; i<n; i++){
        cin >> p;//点の名前
        cin >> r;//隣接点の数
        for(int j=0; j<r; j++){
            cin >> q;//隣接点の名前
            cin >> s;//pとqの間の重み
            A[p][q] = s;
        }
    }
    //↑↑↑

    d[0] = 0;

    Dijkstra(0);

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