Go: // ダイクストラのアルゴリズム
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
	"strings"
)

type color int

const (
	white color = iota // 未訪問
	mst                // MSTとして確定
)

// 頂点
type node struct {
	num     int         // 頂点の番号
	weights map[int]int // 重みMAP
	parent  *node       // MSTへの重み最小の親
	sum     int         // 始点からの距離
	color   color
}

func (p *node) getMinToMst() int {
	if p.parent == nil {
		return math.MaxInt32
	}
	return p.weights[p.parent.num]
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	n := eGetInt(scanner)

	nodes := make([]*node, n)
	for i := 0; i < n; i++ {
		weights := eAtoi((strings.Fields(eGetline(scanner))))
		v := &node{weights[0], make(map[int]int, weights[1]), nil, 0, white}
		for j := 0; j < weights[1]; j++ {
			k := weights[j*2+2] // 相手の頂点名
			w := weights[j*2+3] // 重み
			v.weights[k] = w
		}
		nodes[i] = v
	}

	// 初回はnode[0]がMSTに入るように
	nodes[0].parent = nodes[0]

	for { // 全部チェックするまで

		// どの頂点を新たにMSTに取り込むか

		var minNode *node
		min := math.MaxInt32
		for _, v := range nodes {
			if v.color == mst {
				continue
			}
			if v.getMinToMst() < min {
				min = v.getMinToMst()
				minNode = v
			}
		}
		if minNode == nil {
			// すべて完了している.
			break
		}

		// MSTに追加する頂点決定
		minNode.color = mst
		// 自分の親の合計値と合算する
		minNode.sum = minNode.parent.sum + min

		// MSTに属していない頂点それぞれについて,MSTとの最小の重みの距離を加算
		for _, v := range nodes {
			if v.color == mst {
				continue
			}
			w, ok := v.weights[minNode.num]
			if !ok {
				// minNodeと接してない
				continue
			}

			if w < v.getMinToMst() {
				// minNodeへの距離がもっとも重みが少ないので親を変更
				v.parent = minNode
			}
		}
	}

	for i, v := range nodes {
		fmt.Printf("%d %d\n", i, v.sum)
	}
}

func eGetInt(scanner *bufio.Scanner) int {
	t := eAtoi(strings.Fields(eGetline(scanner)))
	return t[0]
}

func eGetline(p *bufio.Scanner) string {
	if !p.Scan() {
		if err := p.Err(); err != nil {
			log.Fatal(err.Error())
		}
		return ""
	}
	return p.Text()
}

func eAtoi(s []string) []int {
	ints := make([]int, len(s))
	var err error
	for i, e := range s {
		ints[i], err = strconv.Atoi(e)
		if err != nil {
			log.Fatal(err.Error())
		}
	}
	return ints
}

C++: // AtCoder template
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; ++i)

/*
* グラフ構造体
*/
template<typename U>
struct edge{
    int to;
    int from;
    U cost; // 変更
    edge(int to, int from, U cost):to(to), from(from), cost(cost){}
    edge(int to, int from):to(to), from(from), cost(1){}
};

template<typename T>
class Graph{
public:
    vector<vector<edge<T>>> graph;
    int v_size;
    
    // 無向グラフならunDirected = true
    Graph(int n, vector<int> from, vector<int> to, vector<T> cost, bool unDirected){
        if(from.size() != to.size() || to.size() != cost.size()) cout << "Graph constructer detected error.\n";
        graph.assign(n, vector<edge<T>>());
        v_size = n;
        for(int i = 0; i < from.size(); ++i){
            edge<T> tmp(to[i], from[i], cost[i]);
            graph[from[i]].push_back(tmp);
            if(unDirected){
                swap(tmp.from, tmp.to);
                graph[to[i]].push_back(tmp);
            }
        }
    }
    Graph(int n, vector<int> from, vector<int> to, bool unDirected){
        if(from.size() != to.size()) cout << "Graph constructer detected error.\n";
        graph.assign(n, vector<edge<T>>());
        for(int i = 0; i < from.size(); ++i){
            edge<T> tmp(to[i], from[i]);
            graph[from[i]].push_back(tmp);
            if(unDirected){
                swap(tmp.from, tmp.to);
                graph[to[i]].push_back(tmp);
            }
        }
    }

    // BFS, DFS
    vector<bool> visited;
    bool BFS(int start, int goal){
        visited.assign(graph.size(), false);
        queue<pair<int, T>> que;
        que.emplace(start, 0);
        while(!que.empty()){
            int now = que.front().first;
            T depth = que.front().second;
            que.pop();
            visited[now] = true;
            
            if(now == goal){ // 処理記述

                return true;
            }
            
            for(int i = 0; i < graph[now].size(); ++i){
                int next = graph[now][i].to;
                int cost = graph[now][i].cost;
                if(visited[next]) continue;
                que.emplace(next, depth+cost);
            }
        }
        return false;
    }

    bool DFS(int start, int goal){
        visited.assign(v_size, false);
        stack<pair<int, T>> sta;
        sta.emplace(start, 0);
        while(!sta.empty()){
            int now = sta.top().first;
            T depth = sta.top().second;
            sta.pop();
            visited[now] = true;
    
            if(now == goal){ // 処理記述
                
                return true;
            }
            for(int i = 0; i < graph[now].size(); ++i){
                int next = graph[now][i].to;
                int cost = graph[now][i].cost;
                if(visited[next]) continue;
                sta.emplace(next, depth+cost);
            }
        }
        return false;
    }
    
    // ダイクストラ法（による最短経路木構築）
    vector<T> d_d;
    void Dijkstra(int start, int goal, T t_max){
        d_d.assign(graph.size(), t_max);
        d_d[start] = 0;
        priority_queue<pair<T,int>, vector<pair<T,int>>, greater<pair<T, int>> > que;
        que.emplace(0, start);
        while(!que.empty()){
            T dist = que.top().first;
            int now = que.top().second;
            que.pop();
            if(d_d[now] < dist) continue;
            //if(now == goal) return ; // ここの行を失くせばstart全頂点への距離が求められる
            for(int i = 0; i < graph[now].size(); ++i){
                int next = graph[now][i].to;
                int next_cost = graph[now][i].cost;
                if(d_d[next] > d_d[now] + next_cost){
                    d_d[next] = d_d[now] + next_cost;
                    que.emplace(d_d[next], next);
                }
            }
        }
    }

    // ワーシャルフロイド法
    vector<vector<T>> w_d;
    void Warshal_Floyd(T u_max){
        int n = graph.size();
        w_d.assign(n, vector<T>(n, u_max));
        for(int i = 0; i < n; ++i){
            w_d[i][i] = 0;
            for(int j = 0; j < graph[i].size(); ++j){
                int next = graph[i][j].to, dist = graph[i][j].cost;
                w_d[i][next] = dist;
            }
        }
        for(int i = 0; i < n ; ++i){
            for(int j = 0; j < n; ++j){
                for(int k = 0; k < n; ++k){
                    w_d[j][k] = min(w_d[j][k], w_d[j][i] + w_d[i][k]);
                }
            }
        }
    }
};




int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    vector<int> from,to;
    vector<ll> cost;
    rep(i,n){
        int u,k; cin >> u >> k;
        rep(j,k){
            int v,c; cin >> v >> c;
            from.push_back(u);
            to.push_back(v);
            cost.push_back(c);
        }
    }
    Graph<ll> graph(n, from, to, cost, false);
    graph.Dijkstra(0, 0, INT_MAX);
    rep(i,n) cout << i << " " << graph.d_d[i] << "\n";
}