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 <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define ALL(n) begin(n),end(n)
const int INF=1000000000;

using Graph=vector<vector<int>>;

int n;
vector<int> d;

void Dijkstra(const Graph &G){
    // 暫定の最短距離，頂点番号
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> que;
    que.emplace(d[0],0);

    // 距離を確定すべき頂点がなくなるまで続ける
    while(!que.empty()){
        pair<int,int> p=que.top();
        que.pop();
        int v=p.second;
        
        // 最短距離より大きい場合は無視
        if(d[v]<p.first) continue;

        REP(i,n){
            // 辺(v,i)がなければ無視
            if(G[v][i]==INF) continue;

            // 辺(v,i)を採用して距離が短くなるならば，暫定的に採用
            if(d[i]>d[v]+G[v][i]){
                d[i]=d[v]+G[v][i];
                que.emplace(d[i],i);
            }
        }
    }
}

int main(){
    cin>>n;

    // グラフの受け取り
    Graph G(n,vector<int>(n));
    REP(i,n){
        int u,k;
        cin>>u>>k;
        G[u].assign(n,INF);
        REP(j,k){
            int v,c;
            cin>>v>>c;
            G[u][v]=c;
        }
    }

    // d[i]=(無限大) で初期化
    d.assign(n,INF);
    d[0]=0;

    Dijkstra(G);

    REP(i,n){
        cout<<i<<" "<<d[i]<<endl;
    }
}

C++: #include <iostream>

using namespace std;
int M[100][100]; //?????\??????
int n; //n?????¶?????°
static const int WHITE=0; //?????????????????°
static const int GRAY=1; //??°??????????????°
static const int BLACK=2; //????????????????????\
static const int INFTY=(1<<21);  //??£??¨??£??????
void dijkstra()
{
    int color[100];  //????????¶???????¢????
    int d[100]; //????????¶????????????????°?????????????????????????T??????????????????
    for(int i=0;i<n;i++)
       {
          d[i]=INFTY;  //???????§??????¶?????????????????????????????????????§?????????£??????
          color[i]=WHITE;
       }
    d[0]=0; //???????????????????????????d???0
    while(1)
    {
        int r=-1;int minv=INFTY;
        //?????°??????????°????????????\??°??????T???
        for(int i=0;i<n;i++)
        {
            if(color[i]!=BLACK&&d[i]<minv)
            {
                r=i;minv=d[i];
            }
        }
        if(r==-1) break; //?????????????????¶???-1????????´????????????????????????????????????????????????
        color[r]=BLACK; //?????????????°?????????\??????T??????????°±???????????¶??????BLACK
        //?????¶??????T????????°??????????????\?????´??°??????????????¶???
        //??´??°??¶????????¶??????????????°????????£??????????????\????????¶???????????´??°??????
        for(int i=0;i<n;i++)
        {
            if(color[i]!=BLACK&&M[r][i]!=INFTY) //?????????????????\?????????????????????
            {
                if(d[i]>M[r][i]+d[r]) //?????????????????????
                {
                    d[i]=M[r][i]+d[r];
                    color[i]=GRAY;
                }
            }
        }
    }
    for(int i=0;i<n;i++)
    {
        cout<<i<<" "<<(d[i]==INFTY?-1:d[i])<<endl;
    }
}
int main()
{
    while(cin>>n)
    {
        //????§?????????\??????
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
                M[i][j]=INFTY;
        int u,k,v,c;
        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<iostream>
#include<queue>
#define INF 100000000
using namespace std;
int main(){
  int n;cin>>n;
  int u,k,v,c;
  int mp[101][101],d[101];
  for(int i=0;i<=100;i++){
    d[i]=INF;
    for(int j=0;j<=100;j++)mp[i][j]=INF;
  }
    while(u!=n-1){
    cin>>u>>k;
    for(int i=0;i<k;i++){
      cin>>v>>c;
      if(mp[u][v]>c)mp[u][v]=c;
    }
  }
    d[0]=0;
    queue<int>p;
    p.push(0);
    int mn,s=0,cnt=n;
    while(cnt&&!p.empty()){
      s=p.back();
      mn=INF;
      for(int i=0;i<n;i++){
	if(d[i]>=d[s]+mp[s][i]){
	  d[i]=d[s]+mp[s][i];
	  if(mn>d[i])mn=d[i],k=i;
	}
      }
      if(mn!=INF)cnt--,p.push(k);
      else p.pop();
    }
    for(int i=0;i<n;i++)cout<<i<<" "<<d[i]<<endl;
    
  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#define Lens 101
#define Inf 1<<22

using namespace std;
int N;
int w[Lens][Lens],p[Lens],d[Lens];
char c[Lens];

void dijkstra()
{
	d[0] = 0;
	while (true)
	{
		int u = -1;
		int minv = Inf;
		for (int i = 0; i < N; i++)
		{
			if (c[i] == 'w'&&minv > d[i])
			{
				minv = d[i];
				u = i;
			}
		}
		if (u == -1) break;
		c[u] = 'b';
		for (int v = 0; v < N; v++)
		{
			if (c[v] == 'w'&&w[u][v] != Inf)
				d[v] = min(d[v], w[u][v]+d[u]);
		}
	}
}

int main()
{
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		c[i] = 'w';
		d[i] = Inf;
		p[i] = -1;
		int u,n;
		cin >> u >> n;
		for (int j = 0; j < n; j++)
		{
			int v, tw;
			cin >> v >> tw;
			w[u][v] = tw;
		}
	}
	for(int i=0;i<N;i++)
		for (int j = 0; j < N; j++)
		{
			if (w[i][j] == 0)
				w[i][j] = Inf;
		}
	dijkstra();
	for (int i = 0; i < N; i++)
		cout << i <<' '<< d[i] << endl;
	return 0;
}