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

	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<stdio.h>
#define min(a,b) ((a)>(b))?(b):(a)
int main(void){
	int i,j,n,u,k,s,tmp,w,adj[100][100]={0};
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d",&u,&k);
		for(j=0;j<k;j++){
			scanf("%d %d",&tmp,&w);
			adj[u][tmp]=w;
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			if((adj[i][j]==0) && (i!=j)){
				adj[i][j]=100000000;
			}
		}
	}
	for(s=0;s<n;s++){
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				adj[i][j]=min(adj[i][j],adj[i][s]+adj[s][j]);
			}
		}
	}
	for(i=0;i<n;i++){
		printf("%d %d\n",i,adj[0][i]);
	}
	return 0;
}

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

const int INF = 0xfffffff;
const int MAX = 10000;

struct Edge {
	Edge() {};
	Edge(int v, int c) :v(v), c(c) {};
	bool operator < (const Edge& e)const {
		return c > e.c;
	}
	int v;
	int c;
};

int main() {
	int n;
	priority_queue<Edge> graph[MAX];
	vector<Edge> table;
	bool check[MAX] = { false };
	int ary[MAX] = { 0 };

	cin >> n;

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

	Edge e(0, 0);
	table.push_back(e);
	check[0] = true;

	for (int i = 1; i < n; i++) {
		Edge minv(0, INF);
		int erase = 0;

		for (int j = 0; j < table.size(); j++) {
			int v = table[j].v;
			int c = table[j].c;	
			while (!graph[v].empty() && check[graph[v].top().v])graph[v].pop();
			if (graph[v].empty())continue;
			if (c + graph[v].top().c < minv.c) {
				minv.c = c + graph[v].top().c;
				minv.v = graph[v].top().v;
				erase = v;
			}
		}
		table.push_back(minv);
		check[minv.v] = true;
		graph[erase].pop();
	}
	
	for (int i = 0; i < n; i++) {
		ary[table[i].v] = table[i].c;
	}
	for (int i = 0; i < n; i++) {
		cout << i << " " << ary[i] << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<queue>
using namespace std;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
static const int MAX = 10000;
static const int INFTY = (1 << 21);

int n;
vector<pair<int, int> > adj[MAX]; //重み付き有向グラフの隣接リスト表現

void dijkstra(int s){
    priority_queue<pair<int, int> > PQ;
    int d[MAX], color[MAX];
    for(int i = 0; i < n; i++){
        d[i] = INFTY;
        color[i] = WHITE;
    }

    d[s] = 0;
    PQ.push(make_pair(0, s));
    color[s] = GRAY;

    while( !PQ.empty()){
        pair<int, int> f = PQ.top(); PQ.pop();
        int u = f.second;
        color[u] = BLACK;
/*
        //最小値を取り出し、それが最短でなければ無視
        if( d[u] < f.first * (-1)) continue;
*/
        for(int j = 0; j < adj[u].size(); j++){
            int v = adj[u][j].first;
            if( color[v] == BLACK) continue;
            if( d[v] > d[u] + adj[u][j].second ){
                d[v] = d[u] + adj[u][j].second;
                //priority_queue　はデフォルトで大きい値を優先するため -1 をかける
                PQ.push(make_pair(d[v] * (-1), v)); //pqは一つ目の値でソートされるため、第一項に距離を持ってきている
                color[v] = GRAY;
            }
        }
    }

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

int main(){
    cin >> n;
    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;
            adj[u].push_back(make_pair(v, c));
        }
    }

    dijkstra(0);

    return 0;
}

C++: #include <vector>
#include <iostream>
#include <algorithm>
#include <limits>
#include <queue>

using namespace std;
using graph = vector<vector<int>>;


struct edge {
    int src;
    int dst;
    int weight;

    edge(int src, int dst, int w) : src(src), dst(dst), weight(w) {}
};

bool operator < (const edge &a, const edge &b) {
  return a.weight > b.weight;
}


int main() {
    int n;
    cin >> n;

    graph G(n, vector<int>(n, -1));
    for (int i = 0; i < n; ++i) {
        int u, k;
        cin >> u >> k;

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

    // Dijkstra's algorithm (with pritority queue)
    vector<int> d(n, -1);
    vector<bool> visited(n, false);
    priority_queue<edge> Q;

    Q.push(edge(-1, 0, 0));
    while (!Q.empty()) {
        auto e = Q.top(); Q.pop();
        if (visited[e.dst])
            continue;
        d[e.dst] = e.weight;
        visited[e.dst] = true;

        int i = e.dst;
        int minw = numeric_limits<int>::max();
        for (int j = 0; j < n; ++j) {
            if (visited[j] || G[i][j] < 0)
                continue;
            int w = G[i][j] + d[i];
            if (w < minw) {
                minw = w;
                Q.push(edge(i, j, w));
            }
        }
    }

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

    return 0;
}

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1 << 29;

int main() {
  int n;
  cin >> n;

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

  vector<int> dist(n, INF);
  priority_queue<P, vector<P>, greater<P>> que;
  dist[0] = 0;
  que.push(P(0, 0));
  while (!que.empty()) {
    P p = que.top();
    que.pop();

    for (int i = 0; i < edge[p.second].size(); i++) {
      if (dist[edge[p.second][i].second] > p.first + edge[p.second][i].first) {
        dist[edge[p.second][i].second] = p.first + edge[p.second][i].first;
        que.push(
            P(p.first + edge[p.second][i].first, edge[p.second][i].second));
      }
    }
  }

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

  return 0;
}