Go: package main

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

const BIG_COST = 200000

const (
	ST_NOT_YET = iota
	ST_JOINED
)

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

	nNodes := scanInt(sc)

	costs := make([][]int, nNodes)
	graph := make([][]int, nNodes)

	states := make([]int, nNodes)
	costSums := make([]int, nNodes)

	for i := 0; i < nNodes; i++ {
		costs[i] = make([]int, nNodes)
		costSums[i] = BIG_COST
	}

	for i := 0; i < nNodes; i++ {
		u := scanInt(sc)
		k := scanInt(sc)
		graph[u] = make([]int, k)
		for d := 0; d < k; d++ {
			v := scanInt(sc)
			graph[u][d] = v
			costs[u][v] = scanInt(sc)
		}
	}

	costSums[0] = 0
	for {
		minCost := BIG_COST
		var u int

		for i, cost := range costSums {
			if states[i] != ST_JOINED && cost < minCost {
				minCost = cost
				u = i
			}
		}

		if minCost == BIG_COST {
			break
		}

		states[u] = ST_JOINED

		for _, v := range graph[u] {
			cost := minCost + costs[u][v]
			if cost < costSums[v] {
				costSums[v] = cost
			}
		}
	}

	w := bufio.NewWriter(os.Stdout)
	for i, cost := range costSums {
		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
}

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

C++: #include<iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

void dijkstra(){
  int minv;
  int d[MAX], color[MAX];

  for(int i=0;i<n;i++){
    d[i] = INFTY;
    color[i] = WHITE;
  }

  d[0] = 0;
  color[0] = GRAY;
  while(1){
    minv = INFTY;
    int u = -1;
    for(int i=0;i<n;i++){
      if(minv>d[i] && color[i]!=BLACK){
        u=i;
        minv = d[i];
      }
    }
    if(u==-1) break;
    color[u] = BLACK;
    for(int v=0;v<n;v++){
      if(color[v]!=BLACK && M[u][v]!=INFTY){
        if(d[v]>d[u]+M[u][v]){
          d[v]=d[u]+M[u][v];
          color[v]=GRAY;
        }
      }
    }
  }
  for(int i=0;i<n;i++){
    cout << i << " " << (d[i]==INFTY?-1:d[i]) << endl;
  }
}

int main(){
  cin >> n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      M[i][j] = INFTY;
    }
  }

  int k,c,u,v;
  for(int i=0;i<n;i++){
    cin >> u >> k;
    for(int j=0;j<k;j++){
      cin >> v >> c;
      M[u][v] = c;
    }
  }
  dijkstra();
  return 0;
}