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

void dijkstra() {
  int minv;
  int 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 i = 0; i < n; i++) {
      if (minv > d[i] && color[i] != BLACK){
        u = i;
        minv = d[i];
      }
    }
    if ( u == -1) break;
    color[u] = BLACK;
    for(int v = 0; v < n; v++){
      if (color[v] != BLACK && M[u][v] != INFTY){
        if (d[v] > d[u] + M[u][v]) {
          d[v] = d[u] + M[u][v];
          color[v] = GRAY;
        }
      }
    }
  }

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

int main() {
  cin >> n;
  for ( int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      M[i][j] = INFTY;
    }
  }

  int k, c, u, v;
  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<cstdio>
#include<queue>
#include<utility>
#include<vector>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 250;
const int MAXM = 1000;
int n, m;
int vis[MAXN];
struct Edge{
	int to, weight, next;
}edge[MAXM];
int head[MAXN];
int cnt;
int d[MAXN];
void addEdge(int from, int to, int weight){
	edge[cnt].to = to;
	edge[cnt].weight = weight;
	edge[cnt].next = head[from];
	head[from] = cnt++;
}
void SPFA(int start){
	queue<int> q;
	memset(d, INF, sizeof(d));
	memset(vis, 0, sizeof(vis));
	q.push(start);
	d[start] = 0;
	while (!q.empty()){
		int from = q.front(); q.pop();
		vis[from] = 0;
		for (int i = head[from]; i != -1; i = edge[i].next){
			int to = edge[i].to;
			int weight = edge[i].weight;
			if (d[to] > d[from] + weight){
				d[to] = d[from] + weight;
				if (!vis[to]){
					vis[to] = 1;
					q.push(to);
				}
			}
		}
	}
}
int main(){
	int from, to, weight, k;
	while (scanf("%d", &n) != EOF){
		m = 0;
		memset(head, -1, sizeof(head));
		for (int i = 0; i < n; i++){
			scanf("%d%d", &from, &k);
			m += k;
			for (int i = 0; i < k; i++){
				scanf("%d%d", &to, &weight);
				addEdge(from, to, weight);
			}
		}
		SPFA(0);
		for (int i = 0; i < n; i++) printf("%d %d\n", i, d[i]);
	}
	return 0;
}

C++: #include<iostream>
#include<stdio.h>
#define MAX 2001
#define NIL -1
#define B -2
#define W -1
#define G 0
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;

int d[MAX];
int p[MAX];
int color[MAX];
int n;
int u;
int k;
int c;
int v;
int M[MAX][MAX];
queue <int> Q;

void DIJKSTRA() {
	for (int i = 0; i < n; i++) {
	    d[i] = 9000000;
		p[i] = NIL;
		color[i] = W;
	}
	d[0] = 0;
	color[0] = B;
	int s = 0;
	Q.pop();
	int count = 0;
	while (!Q.empty()) {
		count++;
		for (int i = 0; i < n; i++) {
			if (M[s][i] != -1 && color[i] != B) {
				
				if (d[i] > d[s] + M[s][i]) {
					
					d[i] = d[s] + M[s][i];
					p[i] = s;
					color[i] = G;
					
					
				}
			}
		}
		int a = 0;
		int mini = MAX;
		for (int j = 0; j < n; j++) {
			
			if (color[j] == G) {
		
				if(mini>d[j]){
					a = j;
				}
				mini = min(mini, d[j]);
			}

		}
		s = a;
		color[a] = B;
		Q.pop();
		
	}
	
}
int main(){

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

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

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

C++: #include <cstdio>

const int N = 100;
const int INF = 10000001;
int cost[N][N];
int minCost[N] = {0};
bool isDecide[N] = {false};

int getMinIndex(int n) {
        int minIndex = -1;
        int cost = INF;
        for (int i = 0; i < n; i++) {
                if (minCost[i] < cost && !isDecide[i]) {
                        cost = minCost[i];
                        minIndex = i;
                }
        }

        return minIndex;
}

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

        scanf("%d", &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);
                        cost[u][v] = c;
                }
        }
        while (true) {
                int from = getMinIndex(n);
                if (from < 0) {
                        break;
                }
                isDecide[from] = true;
                for (int to = 0; to < n; to++) {
                        if (cost[from][to] < 0 || isDecide[to]) {
                                continue;
                        }
                        int newCost = minCost[from] + cost[from][to];
                        if (newCost < minCost[to]) {
                                minCost[to] = newCost;
                        }
                }
        }
        for (int i = 0; i < n; i++) {
                printf("%d %d\n", i, minCost[i]);
        }

        return 0;
}