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++: #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;
		
	}
	
}