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>
#define INF 1<<30
using std::cin;
using std::cout;
using std::endl;
typedef struct { int vertex, cost; } pair;
pair pqueue[500000], graph[10000][10001];
int mincost[10000], size;
void fswap(pair *x, pair *y) {
  pair tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}
void maxheap(int x) {
  int left = 2 * x, right = 2 * x + 1, minimum = x;
  if (left <= size && pqueue[left].cost<pqueue[x].cost) minimum = left;
  if (right <= size && pqueue[right].cost<pqueue[minimum].cost) minimum = right;
  if (minimum != x) {
    fswap(&pqueue[x], &pqueue[minimum]);
    maxheap(minimum);
  }
}
int extract() {
  while (1) {
    pair x = pqueue[1];
    pqueue[1] = pqueue[size--];
    maxheap(1);
    if (mincost[x.vertex] == INF) {
      mincost[x.vertex] = x.cost;
      return x.vertex;
    }
    if (size <= 0) return INF;
  }
}
void insert(pair x) {
  pqueue[++size] = x;
  int cur = size;
  while (cur != 1 && pqueue[cur].cost<pqueue[cur / 2].cost) {
    fswap(&pqueue[cur], &pqueue[cur / 2]);
    cur /= 2;
  }
}
int main() {
  int n; cin >> n;
  for (int i = 0; i < n; ++i) {
    int u, k; cin >> u >> k;
    for (int j = 0; j < k; ++j) cin >> graph[u][j].vertex >> graph[u][j].cost;
    graph[u][k].cost = INF;
  }
  for (int i = 0; i < n; ++i) mincost[i] = INF;
  insert({ 0,0 });
  while (1) {
    int x = extract();
    if (x == INF) break;
    for (int i = 0; graph[x][i].cost != INF; ++i)
      if(mincost[graph[x][i].vertex]==INF) insert({ graph[x][i].vertex,mincost[x] + graph[x][i].cost });
  }
  for (int i = 0; i < n; ++i) cout << i << " " << mincost[i] << endl;
  return 0;
}

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

// O(ElogE)

// pq<pair> はfirstが大きい順に出てくるのですか？
// s:= 開始ノード  v:= 頂点数  adjlist:= 隣接リスト (first:= コスト   second:= 行先)
vector<int> dijk(int s, int v, vector<vector<pair<int, int> > > adjlist){
    
    priority_queue <pair<int, int> > wait;
    vector<int> result(v, INF);

    //スタート地点を追加
    result[s] = 0;
    wait.push(make_pair(0, s));

    //ダイクストラ本体
    while(!wait.empty()){    //waitが空になるまで

        int nowpoint = wait.top().second;
        int nowcost = -wait.top().first;
        wait.pop();

        if(result[nowpoint] < nowcost) continue;


        //今いる頂点と隣接しているすべての頂点をなめる
        for(int i = 0; i < adjlist[nowpoint].size(); i++){

            int nextpoint = adjlist[nowpoint][i].second;
            int nextcost = nowcost + adjlist[nowpoint][i].first;
            //現時点より安く到達できそうであれば、結果を更新して優先度付きキューに格納
            if(result[nextpoint] > nextcost){
                result[nextpoint] = nextcost;
                wait.push(make_pair(-nextcost, nextpoint));
            }
        }
    }
    
    return result;         //結果列を返す
}

int main(){

    int V; cin >> V;
    vector<vector<pair<int, int> > > adjlist(V);      //first := コスト　second := 行先

    //入力
    for(int i = 0; i < V; i++){
        int gomi; cin >> gomi;
        int k; cin >> k;
        for(int j = 0; j < k; j++){
            int v, c; cin >> v >> c;           // a ,b 間に コスト c の辺がある
            adjlist[i].push_back(make_pair(c, v));
        }     
    }

    vector<int> result(V);
    result = dijk(0, V, adjlist);
    //cout << result[G] << endl;

    for(int i = 0; i < V; i++){
        cout << i << " " << result[i] << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
// N 为邻接矩阵的大小
#define N 10001
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INFTY 1 << 21

using namespace std;

int color[N], d[N], p[N];
vector<pair<int, int> > adj[N];

void dijkstra (int s, int n) {
  priority_queue<pair<int, int> > PQ;

  for (int i = 0; i < n; i++) {
    color[i] = WHITE;
    d[i] = INFTY;
  }

  d[s] = 0;
  p[s] = -1;
  PQ.push(make_pair(0, 0));
  color[0] = GRAY;

  while (PQ.size()) {
    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 && d[u] + adj[u][j].second < d[v]) {
        d[v] = d[u] + adj[u][j].second;
        p[v] = u;
        // 优先队列默认优先较大值，因此要乘以 -1
        PQ.push(make_pair(d[v] * (-1), v));
        color[v] = GRAY;
      }
    }
  }
}

int main () {
  int n, u, v, degree, cost;
  
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> u >> degree;
    
    for (int j = 0; j < degree; j++) {
      cin >> v >> cost;
      
      adj[i].push_back(make_pair(v, cost));
    }
  }

  dijkstra(0, n);

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

  return 0;
}

C++: #include <iostream>
#include <vector>
#include <queue>
static const int MAX = 10000;
static const int INFTY = (1<<20);
static const int WHITE = 0;
static const int BLACK = 1;

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

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

  d[0] = 0;
  PQ.push(std::make_pair(0, 0));

  while(!PQ.empty()) {
    std::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(std::make_pair(d[v] * (-1), v));
      }
    }
  }

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

}


int main() {
  int k, u, v, c;
  std::cin >> n;

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

  dijkstra();
}