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++: //Single Source Shortest Path I
#include <iostream>
#include <climits>
using namespace std;

static const int N = 100;
static const int WHITE = 0;
static const int BLACK = 1;
int n, A[N][N], colors[N], d[N];

void dijkstra() {
    int u, mind;
    for(int i = 0; i < N; i++) {
        colors[i] = WHITE;
        d[i] = INT_MAX;
    }
    d[0] = 0;
    while(1) {
        u = -1;
        mind = INT_MAX;
        for(int i = 0; i < n; i++) {
            if(colors[i] == WHITE && d[i] < mind) {
                u = i;
                mind = d[i];
            }
        }
        if(u == -1) break;
        colors[u] = BLACK;
        for(int i = 0; i < n; i++) {
            if(A[u][i] != -1) {
                d[i] = min(d[i], mind + A[u][i]);
            }
        }
    }

}

int main() {
    int u, k, v, c;
    cin >> n;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            A[i][j] = -1;
        }
    }
    for(int i = 0; i < n; i++) {
        cin >> u >> k;
        for(int j = 0; j < k; j++) {
            cin >> v >> c;
            A[u][v] = c;
        }
    }

    dijkstra();

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

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<vector<int> > vvi;
typedef vector<int> vi;
typedef vector<vector<bool> > vvb;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef pair<string, int> psi;
typedef pair<int, int> pii;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define yn(f) (f?"yes":"no")
#define YN(f) (f?"YES":"NO")
#define Yn(f) (f?"Yes":"No")
#define mod 1000000007
#define intmax 2147483647
#define intmin -2147483648
#define longmax 9223372036854775807
#define longmin -9223372036854775808
int main() {
	int N;
	cin >> N;
	vvi A(N,vi(N,intmax));
	vi color(N,0);
	vi mincost(N,intmax);
	for (int i = 0; i < N; i++)
	{
		int u,k;
		cin >> u>>k;
		A[i].push_back(u);
		for (int j = 0; j < k; j++)
		{
			int v, w;
			cin >> v >> w;
			A[u][v] = w;
		}
	}
	color[0] = 127;
	mincost[0] = 0;
	while (true) {
		int minIndex = -1;
		for (int i = 0; i < N; i++)
		{
			if (color[i]==127&&(minIndex==-1||mincost[i]<mincost[minIndex]))minIndex = i;
		}
		if (minIndex==-1) break;
		color[minIndex] = 255;
		for (int i = 0; i < N; i++)
		{
			if (color[i]!=255&&A[minIndex][i]<intmax) {
				mincost[i] = min(mincost[i],mincost[minIndex]+ A[minIndex][i]);
				color[i] = 127;
			}
		}
	}
	for (int i = 0; i < N; i++)
	{
		cout << i << " " << mincost[i] << endl;
	}
};

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#define INF 1<<30
using namespace std;
int n;
int A[1000][1000];
int d[1000];
bool used[1000];
int D[1000][1000];

void Init(int f){
  for(int i=0;i<f;i++){
    for(int j=0;j<f;j++)D[i][j] = INF;
  }

}

void djkstra(){
  for(int i=0;i<n;i++){
    d[i] = INF;
    used[i] = false;
  }
  d[0] = 0;

  while(true){
    int v = -1;
    for(int i=0;i<n;i++){
      if(!used[i] && (v == -1 || d[v] > d[i]))v = i;
    }
    if(v == -1)break;
    used[v] = true;
    for(int i=0;i<n;i++){
      d[i] = min(d[i],d[v] + D[v][i]);
    }
  }
}



int main(){
  scanf("%d",&n);
  int u,k,C,V;
  Init(n);
 
  for(int i=0;i<n;i++){
      scanf("%d %d",&u,&k);     
      for(int j=0;j<k;j++){
	scanf("%d %d",&V,&C);
	D[u][V] = C;
	D[V][u] = C;
      }     
  }
  
  //for(int i=0;i<n;i++)D[i][i] = 0;
  //for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++)D[i][j] = min(D[i][j],D[i][k] + D[k][j]);

  djkstra();
 
  for(int i=0;i<n;i++){
    printf("%d %d\n",i,d[i]);
  }

  return 0;
}

C++: #include<iostream>

using namespace std;

int n, M[100][100], W = 0, G = 1, B = 2;

void dijkstra () {

    int minv, d[100], color[100], i, u, v;

    for (i = 0; i < n; i++) {
        d[i] = (1 << 21);
        color[i] = W;
    }

    d[0] = 0;
    color[0] = G;

    while (1) {

        minv = (1 << 21);
        u = -1;

        for (i = 0; i < n; i++) {
            if (minv > d[i] && color[i] != B) {
                u = i;
                minv = d[i];
            }
        }

        if (u == -1) {
            break;
        }

        color[u] = B;

        for (v = 0; v < n; v++) {
            if (color[v] != B && M[u][v] != (1 << 21)) {
                if (d[v] > d[u] + M[u][v]) {
                    d[v] = d[u] + M[u][v];
                    color[v] = G;
                }
            }
        }

    }

    for (i = 0; i < n; i++) {
        cout << i << " " << (d[i] == (1 << 21) ? -1 : d[i]) << endl;
    }

}

int main () {

    int k, c, u, v, i, j;

    cin >> n;
    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            M[i][j] = (1 << 21);
        }
    }

    for (i = 0; i < n; i++) {
        cin >> u >> k;
        for (j = 0; j < k; j++) {
             cin >> v >> c;
             M[u][v] = c;
        }
    }

    dijkstra ();

    return 0;

}