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>
#define INF 1e9
using namespace std;
typedef pair<uint32_t,uint32_t> P;

int bitSearchReverse(uint32_t x){
    if(x==0)return -1;
    return 31-__builtin_clz(x);
}
struct RadixHeap{
    vector<P>v[33];
    uint32_t last,sz;
    RadixHeap(){
        last=sz=0;
    }
    void push(P p){
        assert(last<=p.first);
        sz++;
        v[bitSearchReverse(p.first^last)+1].push_back({p.first,p.second});
    }
    P top(){
        return pop(false);
    }
    P pop(bool f=true){
        assert(sz);
        if(!v[0].size()){
            int i=1;
            while(!v[i].size())++i;
            last=min_element(v[i].begin(),v[i].end())->first;
            for(P p:v[i])v[bitSearchReverse(p.first^last)+1].push_back(p);
            v[i].clear();
        }
        P r=v[0].back();
        if(f){
            sz--;
            v[0].pop_back();
        }
        return r;
    }
    int size(){
        return sz;
    }
    bool empty(){
        return sz==0;
    }
    void clear(){
        last=sz=0;
        for(auto a:v)a.clear();
    }
};
struct Graph{
    Graph(int n):E(n),d(n){}
    vector<vector<P>>E;
    vector<uint32_t>d;
    void add_edge(int a,int b,uint32_t c){
        E[a].emplace_back(b,c);
    }
    void dijkstra(int s){
        RadixHeap H;
        fill(d.begin(),d.end(),INF);
        H.push({d[s]=0,s});
        while(H.size()){
            P e=H.top();H.pop();
            if(e.first>d[e.second])continue;
            for(P& a:E[e.second]){
                uint32_t x=a.first,y=a.second+e.first;
                if(y<d[x])d[x]=y,H.push({y,x});
            }
        }
    }
};

main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin>>N;
    Graph G(N);
    for(int i=0;i<N;++i){
        int u,k;
        cin>>u>>k;
        for(int j=0;j<k;++j){
            int v,c;
            cin>>v>>c;
            G.add_edge(u,v,c);
        }
    }
    G.dijkstra(0);
    for(int i=0;i<N;++i)
        cout<<i<<' '<<G.d[i]<<endl;
}

/***************************************

referred
https://github.com/yosupo06/Algorithm/blob/master/datastructure/buf/RadixHeap.h

****************************************/

C++: #include <bits/stdc++.h>
#define int long long

using namespace std;
const int INF = 1e18;

struct edge
{
    int to;
    int cost;
};
using Graph = vector<vector<edge>>;

#define WHITE 0
#define GRAY 1
#define BLACK 2

int n;
Graph G;

void dijkstra(int start)
{
    int seen[10010];
    int dist[10010];

    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
    for (int i = 0; i < n; i++)
    {
        seen[i] = (i == start) ? GRAY : WHITE;
        dist[i] = (i == start) ? 0 : INF;
        pq.push(make_pair(dist[i], i));
    }

    while (!pq.empty())
    {
        auto now = pq.top();
        pq.pop();
        int u = now.second;
        int distU = now.first;

        seen[u] = BLACK;

        for (auto ne : G[u])
        {
            int v = ne.to;
            int cv = ne.cost;
            if (dist[u] + cv < dist[v])
            {
                dist[v] = dist[u] + cv;
                pq.push(make_pair(dist[v], v));
                seen[v] = GRAY;
            }
        }
    }

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

void solve()
{

    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> n;
    G.resize(n);

    for (int i = 0; i < n; i++)
    {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++)
        {
            int v, c;
            cin >> v >> c;
            G[u].push_back((edge){v, c});
        }
    }

    dijkstra(0);
}

signed main()
{
    solve();
    return 0;
}

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

using namespace std;

typedef pair<int,int> P;

struct edge
{
    int to,cost;
    edge(int _to=0,int _cost=0)
    {
        to=_to;cost=_cost;
    }
};

int n;
vector<edge> G[10010];

int d[10010];
const int INF=1e9+7;

void dijkstra(int s)
{
    fill(d,d+n,INF);

    d[s]=0;
    priority_queue<P,vector<P>,greater<P> > q;
    q.push(P(0,s));

    while(!q.empty())
    {
        P tmp=q.top();q.pop();
        int v=tmp.second;
        if(d[v]<tmp.first) continue;
        for(int i=0;i<G[v].size();i++)
        {
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost)
            {
                d[e.to]=d[v]+e.cost;
                q.push(P(d[e.to],e.to));
            }
        }
    }
}

int main()
{

    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    while(cin>>n)
    {
        int a,b,c,dd;
        for(int i=0;i<n;i++)
        {
            G[i].clear();
            cin>>a>>b;
            for(int j=0;j<b;j++)
            {
                cin>>c>>dd;
                G[a].push_back(edge(c,dd));
            }
        }

        dijkstra(0);

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



    return 0;
}