Go: package main

import (
	"fmt"
	"os"
	"bufio"
	"strings"
	"strconv"
)
var MAX = 1000000
type Vertex struct{
	Value int
	Routes map[int]int
	Done bool
}
func NewVertex(value int) *Vertex{
	routes := make(map[int]int)
	// for i, _ := range routes {
	// 	routes[i] = MAX
	// }
	return &Vertex{ value, routes, false }
}

func (v *Vertex) SetRoute(key, weight int) {
	v.Routes[key] = weight
}

type Path struct {
	Key int
	Weight int
}

var count = 0
func ShortestRoutes(list []*Vertex) []int {
	// create result table
	result  := make([]int, len(list))
	// fmt.Println(result)
	for i, _ := range result {
		result[i] = MAX
	}

	queue := make([]Path, 0)
	queue = append(queue, Path{0, 0})
	result[0] = 0

	for len(queue) != 0 {
		count++
		path := queue[0]
		queue = queue[1:]
		for key, weight := range list[path.Key].Routes {
			// fmt.Println(list[path.Key].Routes)
			// set to result
			// fmt.Printf("Path(%d, %d) ? result[%d] => %d, wieght: %d\n", path.Key, path.Weight, key, result[key], weight)
			if path.Weight + weight < result[key] {
				result[key] = path.Weight + weight 
				queue = append(queue, Path{key, result[key]})
			// } else if !list[key].Done {
			// 	queue = append(queue, Path{key, result[key]})
			}
		}
		list[path.Key].Done = true
	}
	return result
}
func main() {
	var n int
	fmt.Scanf("%d", &n)
	list := make([]*Vertex, n)
	scanner := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		scanner.Scan()
		elements := strings.Split(scanner.Text(), " ")
		value, _ := strconv.Atoi(elements[0])
		list[i] = NewVertex(value)
		for j := 2; j < len(elements); j += 2 {
			key, _    := strconv.Atoi(elements[j])
			weight, _ := strconv.Atoi(elements[j + 1])
			list[i].SetRoute(key, weight)
		}
	}

	result := ShortestRoutes(list)
	for i := 0; i < len(result); i++ {
		fmt.Printf("%d %d\n", i, result[i]);
	}
	// fmt.Printf("count: %d\n", count)
}

C++: #include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

//-----------------------------------------

class dijkstra{
  private:
    ll N; // 頂点数
    struct edge{
      ll to; ll cost; // 頂点iからの行き先とそのコスト
    };
    vector<vector<edge>> G; // 辺の隣接リスト
    vector<vector<edge>> F; // 辺の隣接リスト
    vll dis; // sからiへの最小コスト
    vll par; // iの一個前の頂点
    ll inf = 1e18; 
    //pair<sからiへ行くのの暫定最小コスト、i>の優先度付きキュー
    priority_queue<pll, vector<pll>, greater<pll>> que;
  public:
    dijkstra(ll n){
      N = n;
      G.resize(N);
      F.resize(N);
      dis.resize(N);
      par.resize(N);
    }

    // 頂点iからの辺を入力
    void in_edge(ll i, ll to_, ll cost_){
      edge e = {to_, cost_};
      G[i].push_back(e);
    }

    // 辺の逆転
    void rev_edge(){
      for(ll i=0;i<N;i++){
        for(ll j=0;j<G[i].size();j++){
          edge tmp = G[i][j];
          edge in = {i, tmp.cost};
          F[tmp.to].push_back(in);
        }
      }
    }

    // 初期化
    void init(ll n){
      while(!que.empty()) que.pop();

      for(ll i=0;i<n;i++){
        dis[i] = inf; // コストの初期化
        par[i] = i; // 親の初期化
      }
    }

    // 頂点sから各頂点への最短距離の配列を返す
    vll dis_from_s(ll s){
      init(N);

      dis[s] = 0;
      que.push(make_pair(0,s));

      while(!que.empty()){
        pll pai = que.top(); que.pop();
        ll v = pai.second;

        if(dis[v] < pai.first) continue;

        for(ll i=0;i<G[v].size();i++){
          edge tmp = G[v][i];
          if(dis[tmp.to] > dis[v] + tmp.cost){
            dis[tmp.to] = dis[v] + tmp.cost;
            par[tmp.to] = v;
            que.push(make_pair(dis[tmp.to],tmp.to));
          }
        }
      }
      return dis;
    }

    // 各頂点からsへの最短距離への最短距離を返す (有向グラフの辺を逆転し、sからの最短距離を求める)
    vll dis_to_s(ll s){
      init(N);
      rev_edge();
      que.push(make_pair(0,s));

      while(!que.empty()){
        pll pai = que.top(); que.pop();
        ll v = pai.second;

        if(dis[v] < pai.first) continue;

        for(ll i=0;i<F[v].size();i++){
          edge tmp = F[v][i];
          if(dis[tmp.to] > dis[v] + tmp.cost){
            dis[tmp.to] = dis[v] + tmp.cost;
            par[tmp.to] = v;
            que.push(make_pair(dis[tmp.to],tmp.to));
          }
        }
      }
      return dis;
    }

    // sからtまでの最短経路
    vll get_path_s_to_t(ll t){
      vector<ll> res;
      ll i = t;
      while(i != par[i]){
        res.push_back(i);
        i = par[i];
      }
      reverse(ALL(res));
      return res;
    }
};
//-----------------------------------------

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll n;
  cin >> n;
  dijkstra D(n);
  for(ll i=0;i<n;i++){
    ll v, k;
    cin >> v >> k;
    for(ll j=0;j<k;j++){
      ll a, b;
      cin >> a >> b;
      D.in_edge(i,a,b);
    }
  }
  vll tmp = D.dis_from_s(0);
  REP(i,n) cout << i << " " << tmp[i] <<endl;

  return 0;
}