Go: package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
type Node struct {
	cost int
	done bool
}

type Edge struct {
	to, cost int
}

const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	nodes := make([]Node, N)
	for i := 0; i < N; i++ {
		nodes[i].cost = INF
	}
	E := make([][]Edge, N)
	for i := 0; i < N; i++ {
		id, k := sc.nextInt(), sc.nextInt()
		for j := 0; j < k; j++ {
			to, cost := sc.nextInt(), sc.nextInt()
			E[id] = append(E[id], Edge{to, cost})
		}
	}
	nodes[0].cost = 0
	for {
		cur := 0
		minCost := INF
		for i := 0; i < N; i++ {
			n := nodes[i]
			if !n.done && n.cost < minCost {
				cur = i
				minCost = n.cost
			}
		}
		if minCost == INF {
			break
		}
		nodes[cur].done = true
		for i := 0; i < len(E[cur]); i++ {
			to, cost := E[cur][i].to, E[cur][i].cost+nodes[cur].cost
			if !nodes[to].done && cost < nodes[to].cost {
				nodes[to].cost = cost
			}
		}
	}

	for i := 0; i < N; i++ {
		fmt.Fprintln(wtr, i, nodes[i].cost)
	}
	wtr.Flush()
}

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;
    }
}