Go: package main

import (
	"fmt"
	"container/heap"
)

type Node struct {
	Id int
	Dis int
}

type PriorityQueue []*Node

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].Dis < pq[j].Dis
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *PriorityQueue) Push(x interface{}) {
	*pq = append(*pq, x.(*Node))
}

func (pq *PriorityQueue) Pop() interface{} {
	n := len(*pq)
	pop := (*pq)[n-1]
	*pq = (*pq)[0:n-1]
	return pop
}

func main() {
	var n int
	fmt.Scan(&n)

	g := make([][]int, n)
	c := make([][]int, n)
	pq := make(PriorityQueue, 0, n)
	d := make([]int, n)
	for i := 0; i < n; i++ {
		var u,k int
		fmt.Scan(&u)
		fmt.Scan(&k)
		g[u] = make([]int, k)
		c[u] = make([]int, k)
		for j := 0; j < k; j++ {
			fmt.Scan(&g[u][j])
			fmt.Scan(&c[u][j])
		}

		if u == 0 {
			d[u] = 0
		} else {
			d[u] = 1 << 30
		}
		pq.Push(&Node{u, d[u]})
	}
	heap.Init(&pq)

	for pq.Len() > 0 {
		node := heap.Pop(&pq).(*Node)
		for i := 0; i < len(g[node.Id]); i++ {
			nextId := g[node.Id][i]
			nextDis := node.Dis + c[node.Id][i]
			if nextDis < d[nextId] {
				d[nextId] = nextDis
				heap.Push(&pq, &Node{nextId, nextDis})
			}
		}
	}

	for i := 0; i < n; i++ {
		fmt.Println(i, d[i])
	}
}

C++: #include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

using Weight=int;
using DArray=vector<Weight>;
using DMatrix=vector<DArray>;

static const Weight INF=1<<29;

struct Edge {
    size_t src, dst;
    Weight weight;
    Edge() {}
    Edge(size_t src, size_t dst, Weight weight=1):
        src(src), dst(dst), weight(weight)
    {}
};

bool operator<(const Edge &e, const Edge &f) {
    if (e.weight != f.weight) {
        return e.weight > f.weight;
    } else {
        return e.src!=f.src? e.src<f.src : e.dst<f.dst;
    }
}

using Edges=vector<Edge>;
using Vertex=vector<Edge>;
using Graph=vector<Vertex>;

void join(Graph &g, size_t s, size_t d, Weight w=1) {
    // non-directed
    g[s].push_back(Edge(s, d, w));
    g[d].push_back(Edge(d, s, w));
}

void connect(Graph &g, size_t s, size_t d, Weight w=1) {
    // directed
    g[s].push_back(Edge(s, d, w));
}

template <class T>
using lp_queue=priority_queue<T, deque<T>, greater<T>>;

template <typename T, typename U=size_t>
union raw_cast {
    public:
        constexpr raw_cast(T t): _t(t) {}
        operator U() const {
            return _u;
        }

    private:
        T _t;
        U _u;
};

size_t bsr(size_t n) {
    /* Bit scan reverse */
    // logarithmus binarius
    if (!n) return -1;

    size_t res;
    for (res=0; n>>=1; ++res)
        if (!n) return res;

    return res;
}

template <class Index, class T, size_t bucketSize=sizeof(Index)<<3>
struct RadixHeap {
    vector<pair<Index, T>> v[bucketSize|1];
    Index last;
    size_t size_;
    RadixHeap(): last(0), size_(0) {}
    void push(Index n, T t) {
        if (last > n) return;

        ++size_;
        size_t idx=raw_cast<Index>(n);
        idx ^= raw_cast<Index>(last);
        v[bsr(idx)+1].push_back(make_pair(n, t));
    }
    void push(pair<Index, T> p) {
        push(p.first, p.second);
    }
    void pop() {
        if (!size_) return;
        if (!v[0].size()) {
            size_t i; for (i=1; !v[i].size(); ++i);
            last = min_element(v[i].begin(), v[i].end())->first;
            for (const pair<Index, T> &p: v[i]) {
                size_t idx=raw_cast<Index>(p.first);
                idx ^= raw_cast<Index>(last);
                v[bsr(idx)+1].push_back(p);
            }

            v[i].clear();
        }
        --size_;
        v[0].pop_back();
    }
    pair<Index, T> top() {
        if (!size_) return pair<Index, T>();
        if (!v[0].size()) {
            size_t i; for (i=1; !v[i].size(); ++i);
            last = min_element(v[i].begin(), v[i].end())->first;
            for (const pair<Index, T> &p: v[i]) {
                size_t idx=raw_cast<Index>(p.first);
                idx ^= raw_cast<Index>(last);
                v[bsr(idx)+1].push_back(p);
            }

            v[i].clear();
        }
        return v[0].back();
    }
    size_t size() {
        return size_;
    }
    bool empty() {
        return !size_;
    }
    void clear() {
        last = size_ = 0;
        for (size_t i=0; i<=bucketSize; ++i)
            v[i].clear();
    }
};

vector<Weight> shortest_distance(const Graph &g, size_t s) {
    /* Dijkstra */
    size_t V=g.size();
    vector<Weight> d(V, INF); d[s]=0;

    RadixHeap<Weight, size_t> q; q.push(0, s);
    while (!q.empty()) {
        pair<Weight, size_t> p=q.top(); q.pop();
        size_t v=p.second;
        if (d[v] < p.first) continue;

        for (const Edge &e: g[v])
            if (d[e.dst] > d[v] + e.weight) {
                d[e.dst] = d[v] + e.weight;
                q.push(d[e.dst], e.dst);
            }
    }
    return d;
}

int main() {
    size_t n;
    scanf("%zu", &n);

    Graph g(n);
    for (size_t i=0; i<n; ++i) {
        size_t u, k;
        scanf("%zu %zu", &u, &k);

        for (size_t j=0; j<k; ++j) {
            size_t c;
            Weight v;
            scanf("%zu %d", &c, &v);

            connect(g, u, c, v);
        }
    }

    vector<Weight> d=shortest_distance(g, 0);
    for (size_t i=0; i<n; ++i)
        printf("%zu %d\n", i, d[i]);

    return 0;
}

C++: #include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int MAX=105;
const int INF= 1<<30;
int M[MAX][MAX],n,d[MAX],p[MAX],vis[MAX];
void init(){
	for(int i=0;i<n;i++){
		d[i]=INF;
		p[i]=-1;
		vis[i]=0;
	}
	d[0]=0;
}
void dijkstra(){
	init();
	while (true){
		int u=-1;
		int minCost=INF;
		for(int i=0;i<n;i++){
			if(!vis[i] && d[i]<minCost){
				u=i;
				minCost=d[i];
			}
		}
		if(u==-1)break;
		vis[u]=1;
		for(int i=0;i<n;i++){
			if(!vis[i] && M[u][i]!=-1 &&M[u][i]+d[u]<d[i]){
				d[i]=M[u][i]+d[u];
				p[i]=u;
			}
		}
	}
}
int main(){
	cin>>n;
	memset(M,-1,sizeof(M));
	for(int i=0;i<n;i++){
		int u,k,v,c;
		cin>>u>>k;
		for(int j=0;j<k;j++){
			cin>>v>>c;
			M[u][v]=c;
		}
	}
	dijkstra();
	for(int i=0;i<n;i++){
		printf("%d %d\n",i,d[i]);
	}
	return 0;
}

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

int N, M[MAX][MAX];
void dijkstra() {
	int minv;
	int D[MAX], C[MAX];

	for (int i = 0; i < N; i++) {
		D[i] = INFTY;
		C[i] = WHITE;
	}

	D[0] = 0;
	C[0] = GRAY;
	while (true) {
		minv = INFTY;
		int u = -1;
		for (int i = 0; i < N; i++) {
			if (minv > D[i] && C[i] != BLACK) {
				u = i;
				minv = D[i];
			}
		}
		if (u == -1) break;
		C[u] = BLACK;
		for (int v = 0; v < N; v++) {
			if (C[v] != BLACK && M[u][v] != INFTY) {
				if (D[v] > D[u] + M[u][v]) {
					D[v] = D[u] + M[u][v];
					C[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();
}