Go: package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const INF = 1 << 60

type Edge struct {
	to, cost int
}

type Node struct {
	id, cost int
}

type PQ []Node

func (pq PQ) Len() int           { return len(pq) }
func (pq PQ) Less(i, j int) bool { return pq[i].cost < pq[j].cost }
func (pq PQ) Swap(i, j int)      { pq[i], pq[j] = pq[j], pq[i] }

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

func (pq *PQ) Pop() interface{} {
	old := *pq
	n := len(old)
	x := old[n-1]
	*pq = old[0 : n-1]
	return x
}

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	E := make([][]Edge, N)
	for i := 0; i < N; i++ {
		id, k := sc.nextInt(), sc.nextInt()
		E[id] = make([]Edge, k)
		for j := 0; j < k; j++ {
			to, cost := sc.nextInt(), sc.nextInt()
			E[id][j] = Edge{to, cost}
		}
	}

	d := make([]int, N)
	for i := 0; i < N; i++ {
		d[i] = INF
	}
	done := make([]bool, N)
	pq := &PQ{}
	heap.Init(pq)
	d[0] = 0
	heap.Push(pq, Node{0, 0})
	for pq.Len() > 0 {
		cur := heap.Pop(pq).(Node).id
		if done[cur] {
			continue
		}
		done[cur] = true
		for i := 0; i < len(E[cur]); i++ {
			to, cost := E[cur][i].to, E[cur][i].cost+d[cur]
			if !done[to] && cost < d[to] {
				d[to] = cost
				heap.Push(pq, Node{to, cost})
			}
		}
	}

	for i := 0; i < N; i++ {
		fmt.Fprintln(wtr, i, d[i])
	}
	wtr.Flush()
}

C++: #include <cstdint>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

#define GRAPH_SIZE 10000
#define WEIGHT_MAX UINT32_MAX

enum state_t { WHITE, GRAY, BLACK };

static state_t state[GRAPH_SIZE];
static priority_queue<pair<uint32_t, uint32_t>, vector<pair<uint32_t, uint32_t>>, greater<pair<uint32_t, uint32_t>>> min_queue;
static vector<pair<uint32_t, uint32_t>> graph[GRAPH_SIZE];
static uint64_t dist[GRAPH_SIZE];

void single_source_shortest_path(size_t num)
{
  for (uint32_t i = 0; i < num; i++) {
    dist[i] = WEIGHT_MAX;
    state[i] = WHITE;
  }

  state[0] = GRAY;
  dist[0] = 0;
  min_queue.push(make_pair(dist[0], 0));

  while (!min_queue.empty()) {
    pair<uint32_t, uint32_t> min = min_queue.top();
    min_queue.pop();
    uint32_t min_index = min.second;
    if (state[min_index] != BLACK) {
      state[min_index] = BLACK;
      for (uint32_t i = 0; i < graph[min_index].size(); i++) {
        pair<uint32_t, uint32_t> to = graph[min_index][i];
        uint32_t to_index = to.first;
        uint32_t to_weight = to.second;
        if (((dist[min_index] + to_weight) < dist[to_index]) && (state[to_index] != BLACK)) {
          dist[to_index] = dist[min_index] + to_weight;
          min_queue.push(make_pair(dist[to_index], to_index));
          state[to_index] = GRAY;
        }
      }
    }
  }
}

int32_t main()
{
  uint32_t num;
  cin >> num;

  for (uint32_t i = 0; i < num; i++) {
    uint32_t index, len;
    cin >> index >> len;
    for (uint32_t j = 0; j < len; j++) {
      uint32_t connect, weight;
      cin >> connect >> weight;
      graph[index].push_back(make_pair(connect, weight));
    }
  }

  single_source_shortest_path(num);

  for (uint32_t i = 0; i < num; i++) {
    cout << i << " " << dist[i] << endl;
  }

  return 0;
}

C++: #include<iostream>
#include<vector>
#include<queue>
#include <bitset>
using namespace std;
template< typename FirstType, typename SecondType >
struct PairComparator {
  bool operator()( const pair<FirstType, SecondType>& p1, const pair<FirstType, SecondType>& p2 ) const 
    {  
		return p1.first > p2.first;
    }
};
bool inMST(vector< std::pair<int,int> > & MST,int j) {
	for (int k=0;k<(int)MST.size();++k){
		if(j == MST[k].second)
			return true;
	}
	return false;
}
int main(){
	int n;
	cin >> n;
	//vector<int> E(n*n,-1);
	vector<vector<pair<int,int> > > edge(n);
	vector<int> DPG(n,-1);
	vector< std::pair<int,int> > MST;
	std::bitset<10000> flg;

	{
		for(int j=0;j<n;++j) {
			int u,k; 
			cin >> u >> k;
			edge[u].resize(k);
			for(int i=0;i<k;++i){
				int v,c;
				cin >> v >> c;
				edge[u][i] = make_pair(v,c);
			}
		}
	}
	priority_queue<pair<int,pair<int,int> >,vector< pair<int,pair<int,int> > >,
		PairComparator<int,pair<int,int> > > r;

	int cost = 0;
	int i=0;
	MST.push_back(pair<int,int>(i,i));
	flg.set(i);
	DPG[i] = 0;
	while((int)MST.size() < n) {
		int ii=i*n;
//		for (int j=0;j<n;++j) 
		for (int p=0;p<(int)edge[i].size();++p)
		{
			pair<int,int> add = std::make_pair(i,edge[i][p].first);
//			if (!inMST(MST,add.second))
			if (!flg.test(edge[i][p].first))
			{
				r.push(std::pair<int,std::pair<int,int> >(edge[i][p].second+DPG[i],add));
			}
		}
		pair<int,pair<int,int> > top;
		while (!r.empty()) {
			top = r.top();
			r.pop();
//			if (!inMST(MST,top.second.second))
			if (!flg.test(top.second.second))
			{
				break;
			}
		}
		cost += top.first;
		MST.push_back(top.second);
		flg.set(top.second.second);
		i = top.second.second;
		if (DPG[top.second.first] < 0){
			::_DEBUG_ERROR("invalid");
		}
		DPG[i] = top.first;
//		for(int j=0;j<n;++j)
		for (int p=0;p<(int)edge[i].size();++p)
		{
			int j = edge[i][p].first;
			if (DPG[j] < 0)continue;
			DPG[j] = std::min(DPG[j],DPG[i] + edge[i][p].second);
		}
	}
	for (int j=0;j<n;++j) {
		cout << j << " " <<  DPG[j] << endl;
	}
}