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++: //Dijkstra
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
typedef pair<int, int> P;
int n, dis[101], n_left;
vector< vector<P> > G(101);
priority_queue< P, vector<P>, greater<P> > heap;
bool visited[101];

int main(){
    int u, v, k, w;

    scanf("%d", &n);
    n_left = n;
    for(int i=0; i<n; i++){
        scanf("%d %d", &u, &k);
        for(int j=0; j<k; j++){
            scanf("%d %d", &v, &w);
            G[u].push_back(P(w, v));
        }
    }
    memset(visited, 0, sizeof(visited));
    memset(dis, 127, sizeof(dis));

    dis[0] = 0;
    heap.push(P(0, 0));
    while(!heap.empty() && n_left>0){
        P top = heap.top();
        heap.pop();
        if(!visited[top.second]){
            u = top.second;
            visited[u] = true;
            --n_left;
            for(int i=0; i<G[u].size(); i++){
                v = G[u][i].second;
                w = dis[u] + G[u][i].first;
                if(!visited[v] && w < dis[v]){
                    heap.push(P(w, v));
                    dis[v] = w;
                }
            }
        }
    } 
    for(int i=0; i<n; i++){
        printf("%d %d\n", i, dis[i]);
    }
    return 0;
}

C++: #include <iostream>
using namespace std;

const int MAX_N = 100;
const int INF = (1 << 21);

int N;
int A[MAX_N][MAX_N];
int d[MAX_N], c[MAX_N];

void dj() {
  d[0] = c[0] = 0;

  while (1) {
    int cost = INF;
    int cur = -1;

    for (int i = 0; i < N; i ++) {
      if (c[i] != 1 && d[i] < cost) {
        cost = d[i];
        cur = i;
      }
    }

    if (cur == -1) break;
    c[cur] = 1;

    for (int v = 0; v < N; v++) {
      if (c[v] != 1 && A[cur][v] != INF) {
        if (d[cur] + A[cur][v] < d[v]) {
          d[v] = d[cur] + A[cur][v];
          c[v] = 0;
        }
      }
    }
  }

  for (int i = 0; i < N; i++)
    cout << i << ' ' << d[i] << endl;
}

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++)
      A[i][j] = INF;
    d[i] = INF;
    c[i] = -1;
  }

  for (int i = 0; i < N; i++) {
    int cur, k; cin >> cur >> k;

    for (int j = 0; j < k; j++) {
      int u, v;
      cin >> u >> v;
      A[cur][u] = v;
    }
  }

  dj();

  return 0;
}

C++: #include<iostream>
using namespace std;

#define INFTY (1 << 30)

//???????????????
enum Color {
	WHITE,
	GRAY,
	BLACK,
};


//SSSP
void Dijkstra(int verValWeight[][100], int verNum) {

	//???????¨????
	int distance[100];
	Color color[100];
	int parent[100];
	for (int i = 0; i < verNum; i++) {
		color[i] = WHITE;
		distance[i] = INFTY;
		parent[i] = -1;
	}
	distance[0] = 0;

	//SSSP??????
	while (true) {

		//??°??¬????????????????????????????°?????????????????????¶
		int min_cost = INFTY;
		int subScript;
		for (int i = 0; i < verNum; i++) {
			if (color[i] != BLACK && distance[i] < min_cost) {
				min_cost = distance[i];
				subScript = i;
			}
		}

		//??????
		if (min_cost == INFTY)
			break;

		//?????????????????????
		color[subScript] = BLACK;

		//??£??\?????°??¬??????
		for (int i = 0; i < verNum; i++) {
			if (color[i] != BLACK && verValWeight[subScript][i] != INFTY) {
				if (distance[subScript] + verValWeight[subScript][i] < distance[i]) {
					distance[i] = distance[subScript] + verValWeight[subScript][i];
					parent[i] = subScript;
					color[i] = GRAY;
				}
			}
		}
	}

	//??????
	int weight_sum = 0;
	for (int i = 0; i < verNum; i++) {
		cout << i << " " << distance[i] << endl;
	}
}


int main() {

	int verNum;
	int verValWeight[100][100];
	int parent[100];

	//???????¨????
	cin >> verNum;
	for (int i = 0; i < verNum; i++)
		for (int j = 0; j < verNum; j++)
			verValWeight[i][j] = INFTY;

	//??\?????????
	for (int i = 0; i < verNum; i++) {
		int verVal, outNum;
		cin >> verVal >> outNum;
		for (int j = 0; j < outNum; j++) {
			int outVerVal, weight;
			cin >> outVerVal >> weight;
			verValWeight[i][outVerVal] = weight;
		}
	}

	//SSSP
	Dijkstra(verValWeight, verNum);

	return 0;
}

C++: #include <iostream>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli> > mat;
typedef vector<vector<bool> > matb;
typedef vector<string> vst;
typedef pair<lli,lli> pll;
typedef pair<double,double> pdd;
typedef vector<map<lli,lli> > graph;

lli n;
graph g;
lli u,k,v,c;
priority_queue<pll,vector<pll>,greater<pll> > q;
vbl vis;
vll ans;

int main(){
    cin >> n;
    g = graph(n);
    for(lli i = 0;i < n;i++){
        cin >> u >> k;
        for(lli i = 0;i < k;i++){
            cin >> v >> c;
            g[u][v] = c;
        }
    }
    vis = vbl(n);
    ans = vll(n);
    q.push(pll(0,0));
    while(!q.empty()){
        lli d = q.top().first;
        lli p = q.top().second;
        q.pop();
        if(vis[p]) continue;
        vis[p] = true;
        ans[p] = d;
        for(auto itr = g[p].begin();itr != g[p].end();itr++){
            if(!vis[itr->first]) q.push(pll(d+itr->second,itr->first));
        }
    }
    for(lli i = 0;i < n;i++) cout << i << " " << ans[i] << endl;
    return 0;
}