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 <cassert>
#include <climits>
#include <algorithm>
#include <iostream>
#include <vector>
#include <list>
#include <string>
#include <queue>
#include <set>

/*
?§????????????¢0??§???????¢????
??????????¢????????????????????????¶????????????????????§???????°????????????§??°?????????????????£???????????????????¢????
while(????????????????????????????????§)
    list = ???????????????.Get????°?????????????????????????
    for(list)
        ?????????????????????
*/

class TVertex;
struct TPath
{
    int Cost;
    TVertex* Target;
    TPath(TVertex* ATarget, int ACost)
     : Target(ATarget), Cost(ACost) {}
    bool operator<(const TPath& Right)const
    {
        if(this->Cost  < 0) return false;
        if(Right.Cost < 0) return true;
        return this->Cost < Right.Cost;
    }
    bool operator>(const TPath& Right)const
    {
        return !((*this) < Right);
    }
};
class TVertex
{
    int FIndex;
    std::priority_queue<TPath, std::vector<TPath>, std::greater<TPath> > FList;
    int FDistance;

public:
    TVertex(int Index)
     : FIndex(Index), FDistance(INT_MAX)
    {}
    void Reserve(int Size)
    {
        // FList.reserve(Size);
    }
    void AddPath(const TPath& Path)
    {
        FList.push(Path);
    }
    void SortPath()
    {
        // std::sort(FList.begin(), FList.end(), Compare);
    }
    void PrintDistance(std::ostream& out)const
    {
        out << FIndex << " " << FDistance << std::endl;
    }
    int GetMinCostPath()const
    {
        if(FList.empty()) return INT_MAX;
        return FList.top().Cost + FDistance;
    }
    void PickupMinCostPath(int MinCost, std::list<TPath>& List)
    {
        while(FList.empty() == false && FList.top().Cost + FDistance == MinCost){
            List.push_back(TPath(FList.top().Target, FList.top().Cost + FDistance));
            FList.pop();
        }
    }
    bool SetDistance(int Distance)
    {
        if(FDistance < Distance) return false;
        FDistance = Distance;
        return true;
    }
};
class TGraph
{
    std::vector<TVertex*> FTable;
    std::set<TVertex*> FShortest;
    void Init(int n)
    {
        assert(n > 0);
        FTable.resize(n);
        for(int i = 0; i < n; ++i){
            FTable[i] = new TVertex(i);
        }
    }
    static bool CompareMinCost(const TVertex* Left, const TVertex* Right)
    {
        return Left->GetMinCostPath() < Right->GetMinCostPath();
    }
    void AddShortest(TVertex* Vertex, int Distance)
    {
        if(Vertex->SetDistance(Distance)){
            FShortest.insert(Vertex);
        }
    }
    std::list<TPath> PickupMinCostPath(int MinCost)
    {
        std::list<TPath> Result;
        for(std::set<TVertex*>::const_iterator It = FShortest.begin();
            It != FShortest.end(); ++It)
        {
            (*It)->PickupMinCostPath(MinCost, Result);
        }
        return Result;
    }
    void SetShortest(const std::list<TPath>& MinCostPathList)
    {
        for(std::list<TPath>::const_iterator It = MinCostPathList.begin();
            It != MinCostPathList.end(); ++It)
        {
            AddShortest(It->Target, It->Cost);
        }
    }
public:
    TGraph(int n)
    {
        Init(n);
    }
    void SetupVertex(std::istream& in)
    {
        int Index;
        in >> Index;
        assert(Index >= 0);
        assert(Index < FTable.size());
        int k;
        in >> k;
        FTable[Index]->Reserve(k);
        for(int i = 0; i < k; ++i){
            int v, c;
            in >> v >> c;
            FTable[Index]->AddPath(TPath(FTable[v], c));
        }
        FTable[Index]->SortPath();
    }
    void SearchShortest()
    {
        FTable[0]->SetDistance(0);
        FShortest.insert(FTable[0]);
        while(FShortest.size() != FTable.size()){
            int MinCost = (*std::min_element(FShortest.begin(), FShortest.end(), CompareMinCost))->GetMinCostPath();
            std::list<TPath> PathList = PickupMinCostPath(MinCost);
            SetShortest(PathList);
        }
    }
    void PrintDistance(std::ostream& out)
    {
        for(int i = 0; i < FTable.size(); ++i){
            FTable[i]->PrintDistance(out);
        }
    }
};

int main()
{
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    int n;
    std::cin >> n;
    TGraph Graph(n);
    for(int i = 0; i < n; ++i){
        Graph.SetupVertex(std::cin);
    }
    Graph.SearchShortest();
    Graph.PrintDistance(std::cout);
    return 0;
    
}