Go: package main

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

//make priority queue
type Item struct {
	id       int
	priority int // this state is priority and distans from start
	index    int
}

type PriorityQueue []*Item

func (pq PriorityQueue) Len() int { return len(pq) }

// we want the ascending-priority-queue.
// So we use less than here.
func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].priority < pq[j].priority
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = j
	pq[j].index = i
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	item.index = -1 //for safety
	*pq = old[0 : n-1]
	return item
}

func (pq *PriorityQueue) update(dist int, id int) {
	for _, i := range *pq {
		if i.id == id {
			if i.priority > dist {
				i.priority = dist
			}
		}
	}
}

// the main code
func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

func dikstra(dist [][]int, n int) []int {
	// preparate priority queue
	inf := 1 << 30
	pq := make(PriorityQueue, n)
	shortests := make([]int, n)
	for i := 0; i < n; i++ {
		pq[i] = &Item{
			id:       i,
			priority: inf,
			index:    i,
		}

		shortests[i] = inf
	}
	pq[0].priority = 0
	shortests[0] = 0
	heap.Init(&pq)

	for pq.Len() > 0 {
		item := heap.Pop(&pq).(*Item)
		shortests[item.id] = item.priority
		for id, d := range dist[item.id] {
			if d != -1 {
				pq.update(item.priority+d, id)
			}
		}
		heap.Init(&pq)
	}
	return shortests
}

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

	// init
	n := nextInt(sc)
	dist := make([][]int, n)
	for i := 0; i < n; i++ {
		dist[i] = make([]int, n)
		for j := 0; j < n; j++ {
			dist[i][j] = -1
		}
	}

	// std Input
	for i := 0; i < n; i++ {
		u := nextInt(sc)
		k := nextInt(sc)
		for j := 0; j < k; j++ {
			v, c := nextInt(sc), nextInt(sc)
			dist[u][v] = c
		}
	}

	shortests := dikstra(dist, n)
	for i, d := range shortests {
		fmt.Printf("%d %d\n", i, d)
	}
}

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

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1 << 29;

int main() {
  int n;
  cin >> n;

  vector<vector<P>> edge(n);
  for (int i = 0; i < n; i++) {
    int u, k;
    cin >> u >> k;
    for (int j = 0; j < k; j++) {
      int v, c;
      cin >> v >> c;
      edge[u].push_back(P(c, v));
    }
  }

  vector<int> dist(n, INF);
  priority_queue<P, vector<P>, greater<P>> que;
  dist[0] = 0;
  que.push(P(0, 0));
  while (!que.empty()) {
    P p = que.top();
    que.pop();

    for (int i = 0; i < edge[p.second].size(); i++) {
      if (dist[edge[p.second][i].second] > p.first + edge[p.second][i].first) {
        dist[edge[p.second][i].second] = p.first + edge[p.second][i].first;
        que.push(
            P(p.first + edge[p.second][i].first, edge[p.second][i].second));
      }
    }
  }

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

  return 0;
}