Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const BIG_COST = 200000

type Path struct {
	node int
	cost int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	nNodes := scanInt(sc)

	// 各頂点につながる頂点一覧を得るための隣接リスト
	graph := make([][]Path, nNodes)

	for i := 0; i < nNodes; i++ {
		u := scanInt(sc)
		k := scanInt(sc)
		graph[i] = make([]Path, k)
		for d := 0; d < k; d++ {
			graph[u][d] = Path{
				node: scanInt(sc),
				cost: scanInt(sc),
			}
		}
	}

	// 0 から各頂点への最小コストを保存する配列
	minCosts := make([]int, nNodes)

	minCosts[0] = 0
	for i := 1; i < nNodes; i++ {
		minCosts[i] = BIG_COST
	}

	// 各頂点が調査済みかどうかを保持する配列
	checked := make([]bool, nNodes)

	// 最小コストのパスを高速に取得するためのヒープ。
	// コストが小さいものほどルートに来るようにする。
	heap := NewHeap(func(a, b Path) bool {
		return a.cost < b.cost
	})

	heap.insert(Path{node: 0, cost: 0})
	for heap.size > 0 {
		u := heap.extractMax()

		// 隣接行列を使っていた時とは違い、ヒープには
		// 同じノードへのパスが複数含まれうる。そのため既によりコストの低い
		// パスが見つかっている場合は無視する。
		if minCosts[u.node] < u.cost {
			continue
		}

		checked[u.node] = true

		for _, v := range graph[u.node] {
			cost := v.cost + u.cost
			if !checked[v.node] && cost < minCosts[v.node] {
				minCosts[v.node] = cost
				heap.insert(Path{node: v.node, cost: cost})
			}
		}
	}

	w := bufio.NewWriter(os.Stdout)
	for i, cost := range minCosts {
		fmt.Fprintf(w, "%d %d\n", i, cost)
	}
	w.Flush()
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

// --- From ALDS1_9_C: Priority Queue

type Heap struct {
	size   int
	heap   []Path
	isHigh func(a, b Path) bool
}

func NewHeap(isHigh func(a, b Path) bool) Heap {
	heap := make([]Path, 1) // 先頭は不使用
	return Heap{size: 0, heap: heap, isHigh: isHigh}
}

func (h *Heap) insert(v Path) {
	h.size += 1
	if h.size > len(h.heap)-1 {
		h.heap = append(h.heap, v)
	} else {
		h.heap[h.size] = v
	}

	for i := h.size; i > 1; {
		parent := i / 2
		if h.isHigh(h.heap[parent], h.heap[i]) {
			break
		}
		h.heap[i], h.heap[parent] = h.heap[parent], h.heap[i]
		i = parent
	}
}

func (h *Heap) extractMax() Path {
	if h.size <= 0 {
		panic("cannot extract from empty heap")
	}

	max := h.heap[1]
	h.heap[1] = h.heap[h.size]
	h.size -= 1
	h.maxHeapify(1)

	return max
}

func (h *Heap) maxHeapify(idx int) {
	left := idx * 2
	right := left + 1
	largest := idx

	if left <= h.size {
		if h.isHigh(h.heap[left], h.heap[idx]) {
			largest = left
		}
		if right <= h.size && h.isHigh(h.heap[right], h.heap[largest]) {
			largest = right
		}
	}

	if largest != idx {
		h.heap[idx], h.heap[largest] = h.heap[largest], h.heap[idx]
		h.maxHeapify(largest)
	}
}

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;
    
}