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()

	route := make([][]Node, n)
	weight := make([]int, n)
	for i := 0; i < n; i++ {
		weight[i] = NIL
	}

	for i := 0; i < n; i++ {
		u := scanInt()
		k := scanInt()
		route[i] = make([]Node, k)
		for j := 0; j < k; j++ {
			route[u][j] = Node{id: scanInt(), weight: scanInt()}
		}
	}

	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 _, nextNode := range route[node.id] {
			if weight[nextNode.id] != NIL {
				continue
			}
			nextNode.weight += node.weight
			heap.Push(h, nextNode)
		}
	}

	for i, w := range weight {
		fmt.Println(i, w)
	}
}

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

#include <cstdio>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define print_array(ary, size) cout << ary[0]; rep1(i, 1, size - 1) cout << ' ' << ary[i]; cout << endl;
typedef long long ll;
typedef unsigned long long ull;

vector<pair<int, int> > adj[10000];
int cost[10000];
int done[10000];

void dijkstra()
{
	priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > PQ;
	pair<int, int> next;	/* first: cost, second: index */
	int index;

	cost[0] = 0;
	PQ.push(make_pair(0, 0));

	while (!PQ.empty()) {
		next = PQ.top();
		PQ.pop();

		index = next.second;

		if (done[index] == 1) continue;
		done[index] = 1;

		rep(i, adj[index].size()) {
			if ((done[adj[index][i].second] == 0)
				&& (cost[adj[index][i].second] > cost[index] + adj[index][i].first)) {
				cost[adj[index][i].second] = cost[index] + adj[index][i].first;
				PQ.push(make_pair(cost[adj[index][i].second], adj[index][i].second));
			}
		}
	}
}

int main()
{
	int n, u, k, v, c;


	cin >> n;
	rep(i, n) {
		cost[i] = 1000000001;
		done[i] = 0;
		cin >> u >> k;
		rep(j, k) {
			cin >> v >> c;
			adj[u].push_back(make_pair(c, v));
		}
	}

	dijkstra();

	rep(i, n) {
		cout << i << ' ' << cost[i] << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
#define INF 0x3f3f3f3f
static const int MAXN=10000;
int vis[MAXN+10],d[MAXN+10];
int n;
vector<pair<int,int> >adj[MAXN];
void dijkstra()
{
    priority_queue<pair<int,int> > PQ;
    memset(d,0x3f,sizeof(d));
    memset(vis,0,sizeof(vis));
    d[0]=0;
    PQ.push(make_pair(0,0));
    vis[0]=1;
    while(!PQ.empty())
    {
        pair<int,int> f=PQ.top();
        PQ.pop();
        int u=f.second;
        vis[u]=2;
        if(d[u]<f.first*(-1))
            continue;
        for(int j=0;j<adj[u].size();j++)
        {
            int v=adj[u][j].first;
            if(vis[v]==2)
                continue;
            if(d[v]>d[u]+adj[u][j].second)
            {
                d[v]=d[u]+adj[u][j].second;
                PQ.push(make_pair(d[v]*(-1),v));
                vis[v]=1;
            }
        }
    }
    for(int i=0;i<n;i++)
        cout<<i<<" "<<(d[i]==INF?-1:d[i])<<endl;
}
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0),cout.tie(0);
    int u,k,v,c;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>u>>k;
        for(int j=0;j<k;j++)
        {
            cin>>v>>c;
            adj[u].push_back(make_pair(v,c));
        }
    }
    dijkstra();
    return 0;
}

C++: #include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)

#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define itn ll
#define int ll
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
///                →,↑,←,↓,↗,↖,↙,↘
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
int i, j, k;

static const int MAX = 100;
static const int White = 0;
static const int Gray = 1;
static const int Black = 2;

vector<pair<int, int>> adj[MAX];
int n;

void dijkstra() {
	int d[MAX], p[MAX], color[MAX];
	priority_queue<pair<int, int>> PQ;
	rep(i, n) {
		color[i] = White;
		d[i] = INF;
	}
	d[0] = 0;
	PQ.push(make_pair(0, 0));
	color[0] = Gray;
	while (!PQ.empty()) {
		pair<int, int> f = PQ.top();
		PQ.pop();
		int u = f.second;
		color[u] = Black;
		if (d[u] < f.first * (-1)) continue;
		rep(j, adj[u].size()) {
			int v = adj[u][j].first;
			if (color[v] == Black) continue;
			if (d[v] > d[u] + adj[u][j].second) {
				d[v] = d[u] + adj[u][j].second;
				PQ.push(make_pair(d[v] * -1, v));
				color[v] = Gray;
			}
		}
	}
	rep(i, n) {
		cout << i << ' ' << (d[i] == INF ? -1 : d[i]) << '\n';
	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin >> n;
	rep(i, n) {
		int u,k;
		cin >> u >> k;
		rep(j, k) {
			int v, c;
			cin >> v >> c;
			adj[u].pb(make_pair(v, c));
		}
	}
	dijkstra();
	return 0;
}