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 <array>
#include <vector>
#include <algorithm>
#include <queue>

int n;
static const int nmax = 20005;
static const int INFTY = (1<<21);
static const int WHITE = 0; // Not visited
static const int GRAY = 1;  // Visited
static const int BLACK = 2; // In MST
using pair = std::pair<int, int>;
std::array<std::vector<pair>, nmax> adjlist;
std::array<int, nmax> d;
std::array<int, nmax> color;

void dijklstra(int s)
{
  color.fill(WHITE);
  d.fill(INFTY);


  auto priority = [](pair x, pair y){return x.second > y.second;};
  std::priority_queue<
    pair,
    std::vector<pair>,
    decltype(priority)
    > pq(priority);

  pq.push(std::make_pair(s, 0));
  color[s] = GRAY;
  d[s] = 0;

  while (!pq.empty())
    {
      auto u = pq.top();
      pq.pop();
      //std::cout << u.first << ' ' << u.second << std::endl;
      if (d[u.first] < u.second)
        continue;

      color[u.first] = BLACK;
      d[u.first] = u.second;

      for (int i=0; i<adjlist[u.first].size(); ++i)
        {
          auto v = adjlist[u.first][i];
          if ( (color[v.first] != BLACK) && ((d[u.first] + v.second) < d[v.first]))
            {
              d[v.first] = d[u.first] + v.second;
              color[v.first] = GRAY;
              pq.push(std::make_pair(v.first, d[v.first]));
            }
        }
    }


}

void print_distance(int v)
{
  dijklstra(v);

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

int main ()
{
  std::cin >> n;

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

  print_distance(0);
}

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];
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;

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;

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]) << 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;
adj[u].push_back(make_pair(v, c));
}
}

dijkstra();

return 0;
}

C++: #include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<queue>
#include<functional>
using namespace std;
int main(){
	int a;
	int b;
	int s;
	int t;
	vector<int> n[10000];
	int nn[10000];
	vector<int> x[10000];
	priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > >y;
	int z;
	long long d[10000];
	int e;
	int c[10000];
	int zz;
	pair<int, int>pai;
	for (int i = 0; i < 10000; i++){
		d[i] = 10000000000009;
		c[i] = 0;
	}
	scanf("%d", &a);
	for (int i = 0; i < a; i++){
		scanf("%d %d", &s, &b);
		for (int j = 0; j < b; j++){
			scanf("%d %d", &t, &e);
			n[s].push_back(t);
			nn[s]++;
			x[s].push_back(e);

		}
	}
	d[0] = 0;
	y.push(std::make_pair(d[0], 0));
	for (int i = 0; y.empty() == 0; i++){
		zz = 0;
		for (int j = 0; y.empty() == 0 && zz == 0; j++){
			pai = y.top();
			z = pai.second;
			if (c[z] == 0)zz++;
			else y.pop();
		}
		if (zz == 0)break;
		c[z] = 1;
		for (int j = 0; j < nn[z]; j++){
			if (d[z] + x[z][j] < d[n[z][j]])
			{
				d[n[z][j]] = d[z] + x[z][j];
				y.push(std::make_pair(d[n[z][j]], n[z][j]));
			}
		}
		y.pop();
	}
	for (int i = 0; i<a; i++)printf("%d %lld\n",i,d[i]);
		return 0;
}

C++: #include <iostream>
#include <cmath>
#include <vector>
#include <set>
#include <string>
#include <algorithm>

constexpr int INF = 10000001;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int n, u, k, vv, cc;
    std::cin >> n;
    std::vector<std::vector<int>> v(n), c(n);
    std::vector<int> d(n), p(n);
    std::set<int> v_s, s;
    for (int i=0; i<n; i++) {
        std::cin >> u >> k;
        for (int j=0; j<k; j++) {
            std::cin >> vv >> cc;
            v[u].push_back(vv);
            c[u].push_back(cc);
        }
        d[i] = INF;
        v_s.insert(i);
    }
    d[0] = 0;
    //v_s.erase(0);

    while (not v_s.empty()) {
        int mind=INF+1;
        int minnode;
        auto iter = v_s.begin();
        for (int i=0; i<v_s.size(); i++,iter++) {
            if (d[*iter] < mind) {
                mind = d[*iter];
                minnode = *iter;
            }
        }
        v_s.erase(minnode);
        s.insert(minnode);
        for (int i=0; i<v[minnode].size(); i++) {
            if (v_s.find(v[minnode][i]) != v_s.end() and mind + c[minnode][i] < d[v[minnode][i]]) {
                d[v[minnode][i]] = mind + c[minnode][i];
                p[v[minnode][i]] = minnode;
            }
        }
    }

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

    return 0;
}