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 <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

class Graph
{
public:
    enum
    {
        WHITE = 0,
        GRAY = 1,
        BLACK = 2,
    };

    Graph() {}
    Graph(int n)
    : color(n, WHITE), M(n), d(n, INFTY)
    {}
    ~Graph() {}

    void dijkstra(int s)
    {
        d[s] = 0;
        priority_queue< pair<int, int> > pq;

        pq.push(make_pair(0, s));
        while (!pq.empty())
        {
            pair<int, int> du = pq.top(); pq.pop(); 

            int u = du.second;
            int minv = -du.first;

            color[u] = BLACK;

            if (d[u] < -minv) continue;

            for (auto dv : M[u])
            {
                int v = dv.first;
                int w = dv.second;
                if (color[v] != BLACK && d[v] > d[u] + w)
                {
                    d[v] = d[u] + w;
                    color[v] = GRAY;
                    pq.push(make_pair(-d[v], v));
                }
            }
        }
    }

    static const int INFTY = 1e9;
    vs32 color;
    vector< vector< pair<int, int> > > M;
    vs32 d;
};

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

    int n;
    cin >> n;

    Graph g(n);

    int u, v;
    int w;
    int c;
    rep (i, n)
    {
        cin >> u >> c;
        rep (j, c)
        {
            cin >> v >> w;
            g.M[u].emplace_back(v, w);
        }
    }

    g.dijkstra(0);
    rep (i, n)
    {
        cout << i << " " << g.d[i] << "\n";
    }
    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
static const int MAX = 10000;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

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

void dijkstra();


int main() {
    int k, u, 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();

}



void dijkstra() {
    priority_queue<pair<int, int> > PQ;
    int color[MAX];
    int d[MAX];
    for ( int i = 0; i < n; i++) {
        d[i] = INFTY;
        color[i] = WHITE;
    }

    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;

        // take the minimum value, ignore if it is not the shortest
        if ( d[u] < f.first * (-1) ) continue;

        for ( int j = 0; j < adj[u].size(); j++ ) {
            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;
                // multiple (-1) because of priority large value in priority_queue
                PQ.push(make_pair(d[v] * (-1), v));
                color[v] = GRAY;
                }
        }
    }

    for ( int i = 0; i < n; i++ ) {
        cout << i << " " << ( d[i] == INFTY ? -1 : d[i] ) << '\n';
    }
}

C++: #include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
static const int MAX = 10000;
static const int INFTY = (1<<20);
static const int WHITE =0;
static const int GRAY =1;
static const int BLACK=2;

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

void dijkstra(){
    priority_queue<pair<int,int> > PQ;
    int color[MAX],i,j;
    int d[MAX];
    for(i=0;i<n;i++){
        d[i]=INFTY;
        color[i]=WHITE;
        }
    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;
        
        for(j=0;j<adj[u].size();j++){
            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;
            }
        }
    }
    
    for(i=0;i<n;i++){
        cout << i << " " << (d[i]==INFTY ?-1:d[i]) << endl;
    }
}

int main(){
    int k,u,v,c,i,j;
    
    cin>>n;
    for(i=0;i<n;i++){
        cin>>u>>k;
        for(j=0;j<k;j++){
            cin>>v>>c;
        adj[u].push_back(make_pair(v,c));
        }
    }
    dijkstra();
    
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
static const int M=10000;
static const int INF=(1<<20);
int n;
vector<pair<int,int > > a[M];
void dijkstra(){
	priority_queue<pair<int,int> > Q;
	int col[M];
	int d[M];
	for(int i=0;i<n;i++){
		col[i]=0;
		d[i]=INF;
	}
	d[0]=0;col[0]=1;
	Q.push(make_pair(0,0));
	while(!Q.empty()){
		pair<int,int>f=Q.top();Q.pop();
		int u=f.second;col[u]=2;
		if(d[u]<f.first*(-1))continue;
		for(int j=0;j<a[u].size();j++){
			int v=a[u][j].first;
			if(col[v]==2)continue;
			if(d[v]>d[u]+a[u][j].second){
				d[v]=d[u]+a[u][j].second;
				Q.push(make_pair(d[v]*(-1),v));
				col[v]=1;
			}
		}
	}
	for(int i=0;i<n;i++)cout<<i<<' '<<(d[i]==INF?-1:d[i])<<endl;
}
int main() {
	int k,u,v,c;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>u>>k;
		for(int j=0;j<k;j++){
			cin>>v>>c;
			a[u].push_back(make_pair(v,c));
		}
	}
	dijkstra();
}