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 <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <functional>

#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

typedef std::pair<int, int> P;

class Edge{
public:
	int to;
	int cost;

	Edge(){
		return;
	}
	~Edge(){
		return;
	}
};

int main(int argc, char **argv){
	std::vector<std::vector<Edge> >  G;
	std::vector<long> min_cost;
	std::priority_queue<P, std::vector<P>, std::greater<P> > que;

	int n, u, k, v, c;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	//FILE *fp = fopen("test.txt", "r");
#endif

	
#if INPUT_FROM_FILE
	ifs >> n;
#else
	std::cin >> n;
#endif
	G.resize(n);
	min_cost.resize(n, 1000000000) ;

	for(int i = 0; i < n; i++){
#if INPUT_FROM_FILE
		ifs >> u >> k;
#else
		std::cin >> u >> k;
#endif
		for(int j = 0; j < k; j++){
#if INPUT_FROM_FILE
			ifs >> v >> c;
#else
			std::cin >> v >> c;
#endif
			Edge e;
			e.to = v;
			e.cost = c;

			G[u].push_back(e);

		}
	}

	min_cost[0] = 0;
	que.push(P(0, 0));

	while(!que.empty()){
		P p = que.top(); que.pop();
		int v = p.second;

		if(min_cost[v] < p.first){ 
			continue;
		}

		for(int i = 0; i < G[v].size(); i++){
			Edge e = G[v][i];
			if(min_cost[e.to] > min_cost[v] + e.cost){
				min_cost[e.to] = min_cost[v] + e.cost;
				que.push(P(min_cost[e.to], e.to));
			}
		}
	}

	for(int i = 0; i < n; i++){
		std::cout << i << " " << min_cost[i] << std::endl;
	}
	return 0;
}

C++: #define RangeFor(i,n) for(int i=0; i<n; ++i)
#define RvRngFor(i,n) for(int i=n-1; i>=0; --i)

#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#include <limits>

using std::vector;
using std::cin;
using std::priority_queue;
using std::pair;
using std::make_pair;


vector<int> sssp(vector<vector<pair<int, int> > > c, int start_node = 0){
    int n = c.size();
    priority_queue<pair<int, int>, vector<pair<int,int> >, std::greater<pair<int, int>> > pq;
    vector<int> temp_dist(n, std::numeric_limits<int>::max());
    pq.push(make_pair(0, start_node));

    for(;!pq.empty();pq.pop()){
        auto t = pq.top();
        auto d = t.first;
        auto u = t.second;


        if(d < temp_dist[u]){
            temp_dist[u] = d;
            auto k = c[u].size();
            RangeFor(j, k) {
                pq.push(make_pair(d + c[u][j].second, c[u][j].first));
            }
        }
    }

    return temp_dist;
}

int main(){
    int n; cin >> n;
    vector<vector< pair<int,int> > > c(n);
    RangeFor(_, n) {
        int u;
        cin >> u;
        int k;
        cin >> k;
        c[u] = vector<pair<int, int> >(k);
        RangeFor(j, k) {
            int v;
            cin >> v;
            int d;
            cin >> d;
            c[u][j] = make_pair(v, d);
        }
    }

//    RangeFor(i, n){
//        RangeFor(j, c[i].size()){
//            std::cout << c[i][j].first << ' ' << c[i][j].second;
//        }
//        std::cout << std::endl;
//    }

    auto res = sssp(c);
    RangeFor(i, n){
        std::cout << i << ' ' << res[i] << std::endl;
    }
    return 0;
}