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++: #include <iostream>
#include <queue>
#include <vector>

struct Edge {
  int dst;
  long long cost;
  Edge() {}
  Edge(int x, long long y) : dst(x), cost(y) {}
};

std::vector<long long> dijkstra(int sv, std::vector<std::vector<Edge>> &G) {
  const long long LINF = 1000000000000000018LL;

  int n = (int)G.size();
  std::vector<long long> dist(n, LINF);
  dist[sv] = 0;

  typedef std::pair<long long, int> PLI;
  std::priority_queue<PLI, std::vector<PLI>, std::greater<PLI>> que;

  que.push(std::make_pair(0LL, sv));

  while (!que.empty()) {
    PLI now = que.top();
    que.pop();
    long long cur_d = now.first;
    long long cur_v = now.second;

    if (dist[cur_v] < cur_d) {
      continue;
    }

    for (int i = 0; i < (int)G[cur_v].size(); i++) {
      int next_v = G[cur_v][i].dst;
      long long cost = G[cur_v][i].cost;
      if (dist[cur_v] + cost < dist[next_v]) {
        dist[next_v] = dist[cur_v] + cost;
        que.push(std::make_pair(dist[next_v], next_v));
      }
    }
  }
  return dist;
}

int main() {
  int n;
  std::cin >> n;
  std::vector<std::vector<Edge>> g(n);
  for (int i = 0; i < n; i++) {
    int u;
    std::cin >> u;
    int k;
    std::cin >> k;
    while (k--) {
      int v, c;
      std::cin >> v >> c;
      g[u].push_back(Edge(v, c));
    }
  }

  std::vector<long long> dist = dijkstra(0, g);
  for (int i = 0; i < n; i++) {
    std::cout << i << " " << dist[i] << std::endl;
  }

  return 0;
}

C++: //ALDS1_12_cにて、AC
#include<bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
int main(){
  int n;
  cin>>n;
  vector<pair<int,int> > adj[10005]; //重み付き有向グラフの隣接リスト表現
  //隣接リストの作成
  int u,k;
  for(int i=0;i<n;i++){
    cin>>u>>k;
    for(int j=0;j<k;j++){
      int v,c;
      cin>>v>>c;
      adj[u].emplace_back(v,c);
    }
  }

  //ここからダイクストラ
  priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > pq;
  vector<bool> fg(n+1000);
  vector<int> cost(n+1000);
  //初期化
  for(int i=0;i<n;i++){
    cost[i]=INF;
    fg[i]=false;
  }
  //出発地点はコスト0
  cost[0]=0;
  pq.emplace(0,0);
 
  //最短経路を検出
  while(!pq.empty()){
    auto now=pq.top(); pq.pop();
    int u=now.second;
    fg[u]=true;

    //最小値を取り出し、それが最短でなければ無視
    if(cost[u]<now.first) continue;
    
    //次の辺へ移動
    for(int j=0;j<adj[u].size();j++){
      int v=adj[u][j].first;
      if(fg[v]) continue;
      if(cost[v]>cost[u]+adj[u][j].second){
        cost[v]=cost[u]+adj[u][j].second;
        //priority_queueはデフォルトで大き値を優先するため、-1をかける。
        pq.emplace(cost[v],v);
      }
    }
  }

  for(int i=0;i<n;i++){
    cout<<i<<" "<<(cost[i]==INFINITY ? -1 : cost[i])<<'\n';
  }
  return(0);
}

C++: #include<cstdio>
#include<stdlib.h>
#include<iostream>

using namespace std;

const int maxn = 105;
int M[maxn][maxn];
int d[maxn];
int p[maxn];
bool visit[maxn];

int main(){
	int n;
	int u,k,v,c;
	cin >> n;
	for(int i = 0;i < n;i++){
		visit[i] = false;
		d[i] = 0x3f3f3f;
		for(int j = 0;j < n;j++){
			M[i][j] = -1;
		}
	}
	
	for(int i = 0;i < n;i++){
		cin >> u >> k;
		for(int j = 0;j < k;j++){
			cin >> v >> c;
			M[u][v] = c;
		}
	}
	
	d[0] = 0;
	int result = 0;
	while(true){
		int u;
		int min_distance = 0x3f3f3f;
		for(int i = 0;i < n;i++){
			if(visit[i])continue;
			if(d[i] < min_distance){
				min_distance = d[i];
				u = i;
			}
		}
		if(min_distance == 0x3f3f3f)break;
		visit[u] = true;
		result += min_distance;
		for(int i = 0;i < n;i++){
			if(visit[i])continue;
			if(M[u][i] == -1)continue;
			if(d[u] + M[u][i] < d[i]){
				d[i] = d[u] + M[u][i];
				p[i] = u;
			}
		}
	}
	for(int i = 0;i < n;i++)cout << i << " " << d[i] << endl;
//	cout << result << endl;
	
}

C++: #include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;


ll M[110][110]; //edge weight
ll color[110];
ll white = 0, gray = 1, black = 2;
ll n; 

void dijkstra(){
  ll d[110];//d[v] vまでの最短経路
  ll minv;
  rep(i, 0, n){
    color[i] = white;
    d[i] = INF;
  }
  d[0] = 0;
  color[0] = gray;
  while(1){
    minv = INF;
    ll u = -1;
    rep(i, 0, n){
      if(minv > d[i] && color[i] != black){// はじめd[i]=0, u = 0, minv = 0
        u = i;
        minv = d[i];
      }
    }
    if(u == -1) break;
    color[u] = black;// 最も重さが小さいほうへすすむ
    rep(v, 0, n){
      if(color[v] != black && M[u][v] != INF){
        if(d[v] > d[u] + M[u][v]){
          d[v] = d[u] + M[u][v]; //d[v]を更新
          color[v] = gray;
        }
      }
    }
  }
  rep(i, 0, n){
    cout << i << " " << d[i] << endl;
  }
}

int main() {
  cin >> n;
  rep(i, 0, n){//始めに辺の重さをマックスに初期化
    rep(j, 0, n) M[i][j] = INF;
  }

  rep(i, 0, n){
    ll u; cin >> u;
    ll k; cin >> k;
    rep(j, 0, k){
      ll v, c; cin >> v >> c;
      M[u][v] = c;//辺の重さを入力
    }
  }

  dijkstra();

  return 0;
}