Go: package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
)

type Item struct {
	value    int // The value of the item; arbitrary.
	priority int // The priority of the item in the queue.
	// The index is needed by update and is maintained by the heap.Interface methods.
	index int // The index of the item in the heap.
}
type PriorityQueue []*Item

func (pq PriorityQueue) Len() int { return len(pq) }
func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].priority < pq[j].priority
}
func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}
func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}
func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

type Q struct {
	pq *PriorityQueue
	ds map[int]int // It has always same value as pq. For random access.
}

func newQ() *Q {
	pq := new(PriorityQueue)
	heap.Init(pq)
	return &Q{
		pq: pq,
		ds: make(map[int]int),
	}
}
func (q *Q) pop() (u, d int) {
	item := heap.Pop(q.pq).(*Item)
	delete(q.ds, item.value)
	return item.value, item.priority
}
func (q *Q) get(u int) (int, bool) { // returns d
	d, ok := q.ds[u]
	return d, ok
}
func (q *Q) set(u, d int) {
	q.ds[u] = d
	for _, item := range *q.pq {
		if item.value != u {
			continue
		}

		item.priority = d
		heap.Fix(q.pq, item.index)
		return
	}
	heap.Push(q.pq, &Item{
		priority: d,
		value:    u,
	})
}
func (q *Q) len() int {
	return len(q.ds)
}

func main() {
	r := bufio.NewReader(os.Stdin)

	var n int
	fmt.Fscan(r, &n)
	cs := make([]map[int]int, n) // []v_i -> c_i
	for h := 0; h < n; h++ {
		var u, k int
		fmt.Fscan(r, &u, &k)
		m := make(map[int]int)
		for i := 0; i < k; i++ {
			var v, c int
			fmt.Fscan(r, &v, &c)
			m[v] = c
		}

		cs[u] = m
	}

	q := newQ()
	q.set(0, 0)
	visited := make(map[int]struct{})
	out := make([]int, n)

	for q.len() > 0 {
		u, d := q.pop()
		for uu, c := range cs[u] {
			// Consider the connection between u and uu.
			if _, ok := visited[uu]; ok {
				continue
			}
			dd := d + c
			if d, ok := q.get(uu); !ok || d > dd {
				q.set(uu, dd)
			}
		}

		out[u] = d
		visited[u] = struct{}{}
	}

	for u, d := range out {
		fmt.Println(u, d)
	}
}

C++: // ALDS1_12_C: Single Source Shortest Path II
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
#define NIL -1
#define INF 1000000
using intpair = std::pair<int,int>;
bool debug = false;

std::vector<std::vector<intpair>> adjacency_list; // pair = (vertex_num, weight)
std::vector<bool> node_stat;
std::vector<int> minimum_cost;
std::priority_queue<intpair, std::vector<intpair>, std::greater<intpair>> que; // pair = (weight, vetrex_num)

void dijkstra(int vertex) {
    if (debug) std::cout << "dijkstra(" << vertex << ")\n";
    // 1. mark as visited
    node_stat.at(vertex) = false;

    // 2. push weights into priority queue.
    for (int i=0; i<adjacency_list.at(vertex).size(); i++) {
        int next = adjacency_list.at(vertex).at(i).first;
        int edge_weight = adjacency_list.at(vertex).at(i).second;
        int weight = minimum_cost.at(vertex) + edge_weight;

        if (debug) std::cout << "next = " << next << ", weight = " << weight << "\n";
        intpair tmp = std::make_pair(weight, next);
        que.push(tmp);
    }

    // 3. get appropriate next_vertex and determine minimum_cost(next_vertex)
    int next = NIL;
    int size = que.size(); // do NOT use .size() when it can change!!!!!!
    for (int i=0; i<size; i++) {
        int cost = que.top().first, next_vertex = que.top().second;
        que.pop(); 
        if (node_stat.at(next_vertex)) {
            if (cost < minimum_cost.at(next_vertex)) {
                minimum_cost.at(next_vertex) = cost;
                next = next_vertex;
                break;
            }
        }
    }
    // 4. end of recursion
    if (next == NIL) return;

    // 5. recurving
    dijkstra(next);
}

int main() {
    int total_node_num; std::cin >> total_node_num;
    adjacency_list.resize(total_node_num);
    node_stat.assign(total_node_num, true);
    minimum_cost.assign(total_node_num, INF);
    minimum_cost.at(0) = 0;

    for (int i=0; i<total_node_num; i++) {
        int vertex, outdegree; std::cin >> vertex >> outdegree;
        for (int j=0; j<outdegree; j++) {
            std::pair<int,int> tmp; std::cin >> tmp.first >> tmp.second;
            adjacency_list.at(vertex).push_back(tmp);
        }
    }

    dijkstra(0);
    for (int i=0; i<minimum_cost.size(); i++) {
        std::cout << i << " " << minimum_cost.at(i) << "\n";
    }
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 100000
#define EMAX 500000
#define INFTY 2000000000
typedef struct {
  int pre,next,x;
}Cost;
int n,d[MAX];
Cost E[EMAX];
void jr(int);

void jr(int cou){
  int i,tmp;

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

  d[0]=0;

  tmp=1;
  while(tmp!=0){
    tmp=0;
    for(i=0;i<cou;i++){
      if(E[i].x+d[E[i].pre]<d[E[i].next]){
	d[E[i].next]=E[i].x+d[E[i].pre];
	tmp=1;
      }
    }
  }
}

int main()
{
  int n,i,j,u,k,v,cou=0;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    for(j=0;j<k;j++){
      E[cou].pre=u;
      scanf("%d %d",&E[cou].next,&E[cou].x);
      cou++;
    }
  }

  jr(cou);

  for(i=0;i<n;i++){
    printf("%d %d\n",i,d[i]);
  }

  return 0;
}

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

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

void dijkstra(int start){
  priority_queue<pair<int,int>> pq;
  for(int i=0;i<n;i++){
    d[i]=INF;;
    p[i]=0;
  }
  d[start]=0;
  pq.push(make_pair(0,0));
  while(!pq.empty()){
    pair<int,int> f=pq.top();pq.pop();
    int u=f.second;
    p[u]=1;
    if(d[u]<f.first*(-1)) continue;

    for(int i=0;i<adj[u].size();i++){
      int v=adj[u][i].first;
      if(p[v]) continue;
      if(d[v]>d[u]+adj[u][i].second){
	d[v]=d[u]+adj[u][i].second;
	pq.push(make_pair(d[v]*(-1),v));
      }
    }
  }
  for(int i=0;i<n;i++){
    cout<<i<<" "<<d[i]<<endl;
  }
}


  

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