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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct edge{int from, to; ll cost;};

const ll MOD = 1000000007;
const double EPS = 1e-9;

map<ll, ll> d;
priority_queue< Pll, vector<Pll>, greater<Pll> > que;
map<ll, vector<Pll> > edges;

void dijkstra(ll start){
    d[start] = 0;
    que.push(Pll(0, start));

    while(!que.empty()){
        Pll v = que.top(); que.pop();
        if(d.find(v.second) != d.end() && d[v.second] < v.first) continue;
        rep(edges[v.second].size()){
            Pll e = edges[v.second][i];
            if(d.find(e.first) == d.end() || d[e.first] > d[v.second] + e.second){
                d[e.first] = d[v.second] + e.second;
                que.push(Pll(d[e.first], e.first));
            }
        }
    }
}

int main(){
    std::ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;

    rep(n){
        ll u, k, c, v;
        cin >> u >> k;
        repp(j, k){
            cin >> v >> c;
            edges[u].emplace_back(v, c);
        }
    }

    dijkstra(0);
    repp(u, n){
        cout << u << " " << d[u] << endl;
    }

}

C++: #include<iostream>
using namespace std;
#define max 100
#define infty 1<<21

int n;
int d[max];
int aa[max][max];
int color[max];

void soya() {
	d[0] = 0;
	while (1) {
		int x = infty;
		for (int i = 0; i < n; i++) {
			if (x != infty) {
				if (d[i] < d[x] && color[i] != 2) {
					x = i;
				}
			}
			else {
				if (d[i] < x && color[i] != 2) {
					x = i;
				}
			}
		}

		if (x == infty) break;
		else {
			color[x] = 2;
			for (int i = 0; i < n; i++) {
				if (aa[x][i] != -1 && d[x] + aa[x][i] < d[i]) {
					d[i] = d[x] + aa[x][i];
				}
			}
		}
	}
}

int main() {
	for (int i = 0; i < max; i++) {
		color[i] = 0;
		d[i] = infty;
	}

	for (int i = 0; i < max; i++) {
		for (int j = 0; j < max; j++) {
			aa[i][j] = -1;
		}
	}

	cin >> n;
	for (int i = 0; i < n; i++) {
		int id;
		int k;
		cin >> id >> k;
		for (int j = 0; j < k; j++) {
			int num1;
			int kyori;
			cin >> num1 >> kyori;
			aa[id][num1] = kyori;
		}
	}

	soya();

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

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i,a,b) for(i=a;i<b;i++)
#define rloop(i,a,b) for(i=a;i>=b;i--)
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
const int inf=1000000001;
const ll INF=1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;
static const int N=100;

int n;
vii m(N,vi(N));
vi d(N,inf);

void dijkstra();

int main(){
	int i,j;
	cin>>n;
	int u,k,v,c;
	loop(i,0,n){
		loop(j,0,n){
			m[i][j]=inf;
		}
	}
	loop(i,0,n){
		cin>>u>>k;
		loop(j,0,k){
			cin>>v>>c;
			m[u][v]=c;
		}
	}
	dijkstra();
	loop(i,0,n){
		cout<<i<<" "<<d[i]<<endl;
	}
}

void dijkstra(){
	int i;
	d[0]=0;
	vi color(n,WHITE);
	color[0]=BLACK;
	int u=0;
	while(1){
		int minv=inf,v=-1;
		loop(i,0,n){
			if(color[i]!=BLACK){
				d[i]=min(d[i],d[u]+m[u][i]);
				if(minv>d[i]){
					minv=d[i];
					v=i;
				}
			}
		}
		if(v==-1){
			break;
		}
		color[v]=BLACK;
		u=v;
	}
	
}

C++: #include <iostream>
using namespace std;
#include <algorithm>
#include <string>
#define INF 1000000

int flg[100];

bool check(int p){

	if (flg[p] == 1) return false;
	return true;
}

int main(void){

	int n;

	cin >> n;
	int u, k;
	int date[100][100]; //date[??????????????????][?????´?????????]
	int dis[100]; //0????????????????????????????????¢

	memset(date, INF, sizeof(date));
	memset(dis, INF, sizeof(dis));
	memset(flg, 0, sizeof(flg));
	date[0][0] = 0;
	dis[0] = 0;
	for (int i = 0; i < n; i++){

		cin >> u >> k;
		for (int j = 0; j < k; j++){

			int v, c;
			cin >> v >> c;
			date[u][v] = c;
		}
	}

	while(1){
		int mini = INF;
		int p = -1;
		for (int i = 0; i < n; i++){
			if (check(i) && mini > dis[i]){
				p = i;
				mini = dis[i];
			}
		}
		if (p == -1) break;
		flg[p] = 1;
		for (int i = 0; i < n; i++){
			if (check(i) && dis[i] > dis[p] + date[p][i]){
				dis[i] = dis[p] + date[p][i];
			}
		}
	}

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