Go: package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

const NIL = -1

type Node struct {
	id     int
	weight int
}

func init() {
	sc.Split(bufio.ScanWords)
}

type NodeHeap []Node

func (h NodeHeap) Len() int           { return len(h) }
func (h NodeHeap) Less(i, j int) bool { return h[i].weight < h[j].weight }
func (h NodeHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *NodeHeap) Push(x interface{}) {
	*h = append(*h, x.(Node))
}

func (h *NodeHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()

	list := make([][]int, n)
	weight := make([]int, n)
	for i := range list {
		list[i] = make([]int, n)
		weight[i] = NIL
		for j := range list[i] {
			list[i][j] = NIL
		}
	}

	for i := 0; i < n; i++ {
		u := scanInt()
		k := scanInt()
		for j := 0; j < k; j++ {
			v := scanInt()
			w := scanInt()
			list[u][v] = w
		}
	}

	start := Node{id: 0, weight: 0}
	h := &NodeHeap{start}
	heap.Init(h)

	for h.Len() > 0 {
		node := heap.Pop(h).(Node)
		if weight[node.id] != NIL {
			continue
		}
		weight[node.id] = node.weight

		for i, w := range list[node.id] {
			if w == NIL {
				continue
			}
			heap.Push(h, Node{id: i, weight: w + node.weight})
		}
	}

	w := bufio.NewWriter(os.Stdout)
	for i := 0; i < n; i++ {
		fmt.Fprint(w, i)
		fmt.Fprint(w, " ")
		fmt.Fprint(w, weight[i])
		fmt.Fprintln(w)
	}
	w.Flush()
}

C++: #include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
const ll MOD = (ll)1e9+7;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
	if(was_output)cout << " ";
	cout << a;
	was_output = true;
}
void outendl(){
	was_output = false;
	cout << endl;
}

class dijkstra{
public:
	int n;
	vvector<pll> edges;
	vector<ll> fast;
	dijkstra(int N):n(N){
		edges.resize(n);
	}

	void add_edge(int from, int to, ll cost){
		edges[from].emplace_back(to, cost);
	}

	void solve(int start){
		priority_queuer<pll> pq;
		fast.assign(n, INFLL);
		pq.emplace(0, 0);
		fast[start] = 0;
		pq.emplace(0, start);
		while(pq.size()){
			pll d = pq.top();
			pq.pop();
			if(d.first!=fast[d.second])continue;
			foreach(i, edges[d.second]){
				ll next_time = d.first + i.second;
				int to = i.first;
				if(fast[to] <= next_time)continue;
				fast[to] = next_time;
				pq.emplace(next_time, to);
			}
		}
	}
};


int main(){
	int n;
	cin >> n;
	dijkstra dij(n);
	rep(i, n){
		int from;
		cin >> from;
		int time;
		cin >> time;
		rep(j, time){
			int to;
			ll cost;
			cin >> to >> cost;
			dij.add_edge(from, to, cost);
		}
	}
	dij.solve(0);
	rep(i, n){
		output(i);
		output(dij.fast[i]);
		outendl();
	}
	return 0;
}

C++: #include <iostream>
using namespace std;

#define N 100
#define INFTY (1<<21)
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], p[N];

void dijkstra(int s){
  int mincost = 0;
  for(int i = 0 ; i < n ; i++){
    color[i] = WHITE;
    d[i] = INFTY;
    p[i] = -1;
  }
  d[s] = 0;
  p[s] = -1;

  while(true){
    mincost = INFTY;
    int u = -1;
    for(int i = 0 ; i < n; i++){
      if(color[i] != BLACK && d[i] < mincost){
        mincost = d[i];
        u = i;
      }
    }
    if(mincost == INFTY){
      break;
    }
    color[u] = BLACK;

    for(int v = 0 ; v < n ; v++ ){
      if(color[v] != BLACK && M[u][v] != INFTY){
        if(d[u] + M[u][v] < d[v]){
          d[v] = d[u] + M[u][v];
          p[v] = u;
          color[v] = GRAY;
        }
      }
    }
  }
}

int main(){
  cin >> n;
  for(int i = 0 ; i < n ; i++){
    for(int j = 0 ; j < n ; j++){
      M[i][j] = INFTY;
    }
    int u, k;
    cin >> u >> k;
    for(int j = 0 ; j < k ; j++){
      int v , c;
      cin >> v >> c;
      M[u][v] = c;
    }
  }
  dijkstra(0);
  /*for(int i = 0; i < n ; i++){
    for(int j = 0 ; j < n ; j++){
      cout << M[i][j] << " " ;
    }
    cout << "\n";
  }*/
  for(int i = 0 ; i < n ; i++){
    cout << i << " " << d[i] << "\n";
  }
  return 0;
}

C++: #include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { -1, 0, 1, 0 };

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

	int n;
	cin >> n;

	vector<vector<pair<int, int>>> g(n);
	for (int i = 0; i < n; i++) {
		int k, v;
		cin >> k >> v;
		for (int j = 0; j < v; j++) {
			int u, c;
			cin >> u >> c;
			g[k].emplace_back(u, c);
		}
	}

	priority_queue<int> pq;
	pq.emplace(0);

	vector<int> dist(n, INF);
	dist[0] = 0;
	vector<bool> used(n);
	while (!pq.empty()) {
		int u = pq.top(); pq.pop();

		if (used[u]) {
			continue;
		}

		used[u] = true;
		for (auto e : g[u]) {
			int next = e.first;
			int cost = e.second;
			if (dist[next] > dist[u] + cost) {
				dist[next] = dist[u] + cost;
				pq.emplace(next);
			}
		}
	}

	for (int i = 0; i < n; i++) {
		cout << i << " " << dist[i] << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define INF (int)1e9
#define INFL (ll)1e11
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

void dijkstra(vector<vector<int>> v, vector<vector<int>> c, vector<int> &d) {
	d[0] = 0;
	priority_queue<P, vector<P>, greater<P>> pq;
	pq.push(P(0, 0));
	while (!pq.empty()) {
		int s = pq.top().second;
		int dis = pq.top().first;
		pq.pop();
		if (dis > d[s]) continue;
		REP(j, v[s].size()) {
			int u = v[s][j];
			int w = c[s][j];
			if (d[u] > d[s] + w) {
				d[u] = d[s] + w;
				pq.push(P(d[u], u));
			}
		}
	}
}

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

	int n;
	cin >> n;
	vector<vector<int>> v(n), c(n);
	REP(i, n) {
		int u, k;
		cin >> u >> k;
		v[u] = vector<int>(k);
		c[u] = vector<int>(k);
		REP(j, k) cin >> v[u][j] >> c[u][j];
	}
	vector<int> d(n, INF);
	dijkstra(v, c, d);
	REP(i, n) {
		cout << i << " " << d[i] << "\n";
	}
	
	return 0;
}