Go: package main

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

type Node struct {
	Id int
	Dis int
}

type PriorityQueue []*Node

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].Dis < pq[j].Dis
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *PriorityQueue) Push(x interface{}) {
	*pq = append(*pq, x.(*Node))
}

func (pq *PriorityQueue) Pop() interface{} {
	n := len(*pq)
	pop := (*pq)[n-1]
	*pq = (*pq)[0:n-1]
	return pop
}

func main() {
	var n int
	fmt.Scan(&n)

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

	g := make([][]int, n)
	c := make([][]int, n)
	pq := make(PriorityQueue, 0, n)
	d := make([]int, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		u, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())
		g[u] = make([]int, k)
		c[u] = make([]int, k)
		for j := 0; j < k; j++ {
			sc.Scan()
			g[u][j], _ = strconv.Atoi(sc.Text())
			sc.Scan()
			c[u][j], _ = strconv.Atoi(sc.Text())
		}

		if u == 0 {
			d[u] = 0
		} else {
			d[u] = 1 << 30
		}
		pq.Push(&Node{u, d[u]})
	}
	heap.Init(&pq)

	for pq.Len() > 0 {
		node := heap.Pop(&pq).(*Node)
		for i := 0; i < len(g[node.Id]); i++ {
			nextId := g[node.Id][i]
			nextDis := node.Dis + c[node.Id][i]
			if nextDis < d[nextId] {
				d[nextId] = nextDis
				heap.Push(&pq, &Node{nextId, nextDis})
			}
		}
	}

	wr := bufio.NewWriter(os.Stdout)
	for i := 0; i < n; i++ {
		wr.WriteString(strconv.Itoa(i))
		wr.WriteString(" ")
		wr.WriteString(strconv.Itoa(d[i]))
		wr.WriteString("\n")
	}
	wr.Flush()
}

C++: // ALDS1_12_C.cpp
// Graph II - Single Source Shortest Path II
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <queue>
using namespace std;

struct Node {
    int v;
    int c;
    Node(int v, int c): v(v), c(c) {}
};

const int maxN = 10000;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
static const int INF = (1<<21);
vector<Node> G[maxN];
vector<int> dist(maxN, INF);
vector<int> p(maxN);
vector<int> color(maxN, WHITE);
priority_queue<pair<int, int>> mq;
int n;

void dijkstra(int x)
{
    dist[x] = 0;
    p[x] = -1;
    mq.push({-dist[x], x});
    while(!mq.empty()) {
        pair<int, int> P = mq.top();
        mq.pop();
        int mindist = -P.first;
        int u = P.second;
        if (color[u] == BLACK) continue;

        for (int i = 0; i < G[u].size(); i++) {
            if (color[u] == BLACK) continue;
            int v = G[u][i].v;
            int c = G[u][i].c;
            if (dist[u] + c < dist[v]) {
                dist[v] = dist[u] + c;
                p[v] = u;
                color[v] = GRAY;
                mq.push({-dist[v], v});
            }
        }
        color[u] = BLACK;
    }
}

int main()
{
    freopen("in7.txt", "r", stdin);
    freopen("out7.txt", "w", stdout);
    cin >> n;
    int u, k;
    int v, c;
    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            cin >> v >> c;
            G[i].push_back(Node(v, c));
        }
    }
    dijkstra(0);
    for (int i = 0; i < n; i++) {
        printf("%d %d\n", i, dist[i]);
    }
    return 0;
}

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

#define _CRT_SECURE_NO_WARNINGS

#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define REP2(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP3(i, x, n) for(decltype(x) i = (x); i <= (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1; i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

const int INF = 1000000000;
const double PI = 3.1415926535897932384626433832795;

// N, E, S, W
const int dx[4] = { 1, 0, -1, 0};
const int dy[4] = { 0, 1, 0, -1};

using LL = long long int;
using LD = long double;
using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;

//==============================================
int n;
vi color, D;
vector<vector<pii>> G;

void print() {
	REP(i, n) {
		cout << i << " " << D[i] << "\n";
	}
}

void solve() {
	priority_queue<int, vector<pii>, greater<pii> > PQ;
	PQ.push(make_pair(0, 0));
	D[0] = 0;

	while (!PQ.empty()) {
		pii p = PQ.top(); PQ.pop();
		int u = p.second;
		color[u] = 2;
		if (D[u] < p.first) {
			continue;
		}

		REP(i, G[u].size()) {
			int j = G[u][i].first;
			int v = G[u][i].second;

			if (color[j] == 2) continue;
			if (D[u] + v < D[j]) {
				D[j] = D[u] + v;
				color[j] = 1;
				PQ.push(make_pair(D[j], j));
			}
		}
	}
	print();
}

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

	cin >> n;

	color.resize(n);
	D.resize(n, INF);
	G.resize(n);

	int u, k, id, c;
	REP(i, n) {
		cin >> u >> k;
		REP(i, k) {
			cin >> id >> c;
			G[u].push_back(make_pair(id, c));
		}
	}

	solve();
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>

using namespace std;

// ---------------------
// repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

// ---------------------
#define INF (1 << 21)
typedef long long ll;

int main() {
  int n;
  cin >> n;

  vector<int> V[n];
  // int E[n][n];
  map<pair<int, int>, int> E;
  int d[n];
  int visited[n];

  priority_queue<pair<int, int> , vector<pair<int, int> >, greater<pair<int, int> > > Q;

  REP(i, n) {
    d[i] = INF;
    visited[i] = 0;
  }

  REP(_, n) {
    int u, k;
    cin >> u >> k;
    REP(__, k) {
      int v, c;
      cin >> v >> c;
      V[u].push_back(v);
      E[make_pair(u, v)] = c;
    }
  }

  d[0] = 0;
  Q.push(make_pair(d[0], 0));
  while (!Q.empty()) {
    int mincost = Q.top().first;
    int minv = Q.top().second;
    Q.pop();

    visited[minv] = 1;
    for (vector<int>::iterator it = V[minv].begin(); it != V[minv].end(); it++) {
      if (E[make_pair(minv, *it)] < INF && d[minv] + E[make_pair(minv, *it)] < d[*it]) {
        d[*it] = d[minv] + E[make_pair(minv, *it)];
        Q.push(make_pair(d[*it], *it));
      }
    }
  }

  REP(i, n) {
    cout << i << " " << d[i] << endl;
  }
  return 0;
}