Go: package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)

	g := makeGraph(n)
	for i := 0; i < n; i++ {
		u := getNextInt(scanner)
		k := getNextInt(scanner)
		for ii := 0; ii < k; ii++ {
			v := getNextInt(scanner)
			c := getNextInt(scanner)
			g[u][v] = c
		}
	}

	ans := make([]int, n)
	im := make(IntMap, 1)
	im.increment(0)
	for len(im) < n {
		min := 1 << 30
		x := -1
		for u := range im {
			for v := 0; v < n; v++ {
				if im.get(v) != 0 {
					continue
				}
				if min > ans[u]+g[u][v] {
					min = ans[u] + g[u][v]
					x = v
				}
			}
		}
		im.increment(x)
		ans[x] = min
	}

	for i := 0; i < n; i++ {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d", i, ans[i]))
	}
	writer.Flush()
}

func makeGraph(n int) [][]int {
	g := make([][]int, n)
	for i := 0; i < n; i++ {
		g[i] = make([]int, n)
		for ii := 0; ii < n; ii++ {
			g[i][ii] = 1 << 30
		}
	}

	return g
}

// IntMap ...
type IntMap map[int]int

func (m IntMap) get(key int) int {
	if _, ok := m[key]; ok {
		return m[key]
	}
	return 0
}
func (m IntMap) increment(key int) {
	if _, ok := m[key]; ok == false {
		m[key] = 0
	}
	m[key]++
}

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