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 <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef pair<ll,P>  PP;
typedef vector<ll> Vector;
typedef vector<Vector> DVector;
typedef priority_queue<P, vector<P>, greater<P>> PQueue;

#define fi          first
#define se          second
#define sfi         se.fi
#define sse         se.se
#define pb          push_back
#define INF         INT_MAX
#define MOD         1000000007
#define bcnt        __builtin_popcount
#define all(x)      (x).begin(),(x).end()
#define uni(x)      x.erase(unique(all(x)),x.end())
#define ub(x,y)     (upper_bound(all(x),y)-x.begin())
#define lb(x,y)     (lower_bound(all(x),y)-x.begin())
#define rep(i,n)    repl(i,0,n-1)
#define usort(x)    sort(all(x))
#define dsort(x)    sort(all(x),greater<ll>())
#define mkp(x,y)    make_pair(x,y)
#define mmax(x,y)   (x>y?x:y)
#define mmin(x,y)   (x<y?x:y)
#define maxch(x,y)  x=mmax(x,y)
#define minch(x,y)  x=mmin(x,y)
#define exist(x,y)  (find(all(x),y)!=x.end())
#define each(itr,v) for(auto itr:v)
#define repl(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);i++)
vector<vector<P>> costs;
ll n;
Vector mincost;
void djk(ll start){
  PQueue pq;
  mincost.resize(n,INF);
  mincost[start] = 0;
  pq.push({0,start});
  while(pq.size()){
    P state = pq.top();pq.pop();
    if(mincost[state.se] < state.fi)continue;
    each(itr,costs[state.se])if(mincost[itr.fi] > mincost[state.se] + itr.se){
      mincost[itr.fi] = mincost[state.se] + itr.se;
      pq.push({mincost[itr.fi],itr.fi});
    }
  }
}

int main(){
  cin.sync_with_stdio(false);
  cin >> n;
  costs.resize(n);
  rep(i,n){
    ll u,k;
    cin >> u >> k;
    rep(j,k){
      ll v,c;
      cin >> v >> c;
      costs[u].pb({v,c});
    }
  }
  djk(0);
  rep(i,n)cout << i << " " << mincost[i] << endl;
}

C++: #include <bits/stdc++.h>
using namespace std;

//def
#define debug(x) cout << #x << ": " << x << '\n'
#define out(x) cout << x << '\n'
#define repeat(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define revrepeat(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr int MOD = 1e9 + 7;
constexpr int INF = __INT_MAX__;               // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

int pre[MAX_N];
long long d[MAX_N];
bool seen[MAX_N];
struct Edge {
    int to;
    long long cost;
};
// require: cost value is positive
// O(nlog|v|)
void dijkstra(int s, vector<vector<Edge>> &graph) {
    fill(pre, pre + MAX_N, -1);
    fill(seen, seen + MAX_N, false);
    fill(d, d + MAX_N, INF);

    auto comPair = [](const P one, const P two) {
        return one.second > two.second;
    };
    // que(v, distance)
    priority_queue<P, vector<P>, decltype(comPair)> que(comPair);
    que.emplace(0, 0);
    d[0] = 0;
    seen[0] = true;

    while (!que.empty()) {
        int u = que.top().first;
        que.pop();

        for (auto e : graph[u]) {
            int v = e.to;
            int c = e.cost;

            if (not seen[v] and d[v] > d[u] + c) {
                d[v] = d[u] + c;
                pre[v] = u;
                que.emplace(v, d[v]);
            }
        }
        seen[u] = true;
    }
};

int main() {
    int n;
    cin >> n;
    vector<vector<Edge>> graph(n);
    int k;
    rep(i, n) {
        cin >> k;
        cin >> k;
        rep(j, k) {
            Edge e;
            cin >> e.to >> e.cost;
            graph[i].push_back(e);
        }
    }
    dijkstra(0, graph);
    rep(i, n) {
        cout << i << ' ' << d[i] << endl;
    }
}

C++: 
#include<iostream>
#include<cstdio>
#include<set>
#include<queue>
#include<cstring>
#include<algorithm>
typedef long long ll;
#define inf 1000000000
using namespace std;


struct _node
{
	ll v,w;
	//:v(a),w(b)
	_node(ll a=0,ll b=0)
	{
		v=a;
		w=b;
	
	};
	bool operator <(const _node & other) const
	{
		return other.w<w;
	}
	
}node;

vector<_node> A[10500];
bool mark[10500];
ll dis[10500];

priority_queue<_node> Q;

void add(ll a,ll b,ll c)
{
	//cout<<a<<" "<<b<<" "<<c<<endl; 
	A[a].push_back(_node(b,c));
	//cout<<A[a][0].w<<endl;
	
}


void dlsj(ll n)
{
	//while(!Q.empty())Q.pop();
	ll v,v1;
	_node tmp;
	for(int i=0;i<n;i++)dis[i]=inf;

	dis[0]=0;
	Q.push(_node(0,0));
	
	while(!Q.empty())
	{
		tmp=Q.top();
		Q.pop();
		v=tmp.v;
		//cout<<v<<endl;
		//cout<<A[v].size()<<endl;
		if(mark[v])continue;
		mark[v]=1;
		for(int i=0;i<A[v].size();i++)
		{
			
			if(mark[A[v][i].v])continue;
			v1=A[v][i].v;
			//cout<<i<<" "; 
			//cout<<dis[2]<<" "<<dis[A[v][i].v]<<" "<<dis[v]+A[v][i].w<<endl;
			//cout<<A[v][i].v<<endl;
			if(dis[v1]>dis[v]+A[v][i].w)
			{
				
				dis[v1]=dis[v]+A[v][i].w;
				
				Q.push(_node(A[v][i].v,dis[v1]));
				
			}
			
			
			
			
		} 
		
		
	}
	
	
	
	
}




int main()
{
	ll n;
	scanf("%lld",&n);
	add(0,0,0);
	for(int i=1;i<=n;i++)
	{
		ll u,k,a,b;
		scanf("%lld%lld",&u,&k);
		while(k--)
		{
			scanf("%lld%lld",&a,&b);
			add(u,a,b);
		}
		
		
		
		
	} 
	dlsj(n);
	for(int i=0;i<n;i++)
	{
		//cout<<"e"<<endl;
		cout<<i<<" "<<dis[i]<<endl;
		
	}
	
}