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>
#include<cstdio>
#include<climits>
#include<cstring>
#define INF INT_MAX
using namespace std;
typedef unsigned long long ull;

 
void Init(int f){
  for(int i=0;i<=f+50;i++){
    for(int j=0;j<=f+50;j++)D[i][j] = INF;
  }
}
 
int main(){
int n;
int A[1000][1000];
ull D[1000][1000];
  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]);
  for(int i=0;i<n;i++){
    cout << i << " " << D[0][i] << endl;
  }
  
  return 0;
}

C++: #include <iostream>
using namespace std;
#define N 100
#define INFTY (1<<21)
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];

void dijkstra() {
    int minv;
    int d[N], color[N];

    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 <bits/stdc++.h>

using namespace std;
typedef pair<int, int> P;

struct edge {
    int t, c;
    edge(int t, int c): t(t), c(c) {}
};

const int INF = 1e9;
int n, u, k, v, c;
vector<edge> G[100];
int d[100];

void dijkstra(int s) {
    fill(d, d + n, INF);
    d[s] = 0;

    priority_queue<P, vector<P>, greater<P> > que;
    que.push(P(0, s));
    while (!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        for (int i = 0; i < G[v].size(); i++) {
            edge e = G[v][i];
            if (d[e.t] <= d[v] + e.c) continue;
            d[e.t] = d[v] + e.c;
            que.push(P(d[e.t], e.t));
        }
    }
}

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

    dijkstra(0);

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

    return 0;
}

C++: #include<iostream>
using namespace std;
#include<stdio.h>
#include<climits>

#define INFTY INT_MAX

int main()
{
    int n, m, i, j, a, w;
    int* adj[100];
    int* dist[100];
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%d %d", &i, &m);
        adj[i] = new int [m + 1];   // adjacensy list.
        dist[i] = new int [m + 1];
        for(j = 0; j < m; j++){
            scanf("%d %d", &a, &m);
            adj[i][j] = a;
            dist[i][j] = w;
        }
        adj[i][m] = -1;
        dist[i][m] = -1;
    }

    int *d, *prev, *Q;
    d = new int [n];
    prev = new int [n];
    Q = new int [n];
    for(i = 0; i < n; i++){ d[i] = INFTY; prev[i] = -1; Q[i] = i; }
    int rest = n;

    int u, v, min;
    d[0] = 0;  // 0 is start.
    while(rest > 0){
        min = INFTY;
        for(i = 0; i < n; i++){
            if(min > d[i] && Q[i] >= 0){ min = d[i]; u = i; }
        }
        Q[u] = -1;
        rest--;
        for(j = 0; adj[u][j] >= 0; j++){
            v = adj[u][j];
            if(d[v] > d[u] + dist[u][j]){
                d[v] = d[u] + dist[u][j];
                prev[v] = u;
            }
        }
    };
    for(i = 0; i < n; i++){ printf("%d %d\n", i, d[i]); }
    for(i = 0; i < n; i++){
        delete adj[i]; delete dist[i]; }
    delete d;
    delete prev;
    delete Q;

    return 0;
}

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

struct Vertex {
    vector<pll> node;
};

Vertex V[105];
ll C[105];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    REP(i, N) {
        ll n, k;
        cin >> n >> k;
        REP(_, k) {
            ll v, c;
            cin >> v >> c;
            V[n].node.push_back(pll(v, c));
        }
    }
    REP(i, N) {
        C[i] = INF;
    }
    priority_queue<pll, vector<pll>, function<bool(pll, pll)>> q([](pll a, pll b) { return a.second > b.second; });
    q.push(pll(0, 0));
    C[0] = 0;
    while (!q.empty()) {
        pll t = q.top();
        q.pop();
        if (C[t.first] < t.second)
            continue;
        for (auto &n : V[t.first].node) {
            ll nxt = n.first;
            ll cost = n.second + t.second;
            if (C[nxt] <= cost)
                continue;
            C[nxt] = cost;
            q.push(pll(nxt, cost));
        }
    }

    REP(i, N) {
        cout << i << " " << C[i] << endl;
    }
    return 0;
}