Go: package main

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

const NIL = -1

type Node struct {
	id     int
	weight int
}

func init() {
	sc.Split(bufio.ScanWords)
}

type NodeHeap []Node

func (h NodeHeap) Len() int           { return len(h) }
func (h NodeHeap) Less(i, j int) bool { return h[i].weight < h[j].weight }
func (h NodeHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *NodeHeap) Push(x interface{}) {
	*h = append(*h, x.(Node))
}

func (h *NodeHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()

	route := make([][]Node, n)
	weight := make([]int, n)
	for i := 0; i < n; i++ {
		weight[i] = NIL
	}

	for i := 0; i < n; i++ {
		u := scanInt()
		k := scanInt()
		route[i] = make([]Node, k)
		for j := 0; j < k; j++ {
			route[u][j] = Node{id: scanInt(), weight: scanInt()}
		}
	}

	start := Node{id: 0, weight: 0}
	h := &NodeHeap{start}
	heap.Init(h)

	for h.Len() > 0 {
		node := heap.Pop(h).(Node)
		if weight[node.id] != NIL {
			continue
		}
		weight[node.id] = node.weight

		for _, nextNode := range route[node.id] {
			if weight[nextNode.id] != NIL {
				continue
			}
			nextNode.weight += node.weight
			heap.Push(h, nextNode)
		}
	}

	for i, w := range weight {
		fmt.Println(i, w)
	}
}

C++: #include <iostream>
#include <stdio.h>
#include <vector>

using namespace std;

struct Wside{
	int vertex;
	int weight;
	Wside(int a, int b){
		vertex=a; weight=b;
	}
};

vector<Wside>* info;
vector<int> scanned;
int* result, *candidates;
int n;

bool isScanned(int v){
	for(int i=0,sz=scanned.size(); i<sz; ++i){
		if(v==scanned[i]) return 1;
	}
	return 0;
}

int scan(){
	int nextvtx;
	for(int j=0, scn=scanned[scanned.size()-1], sz=info[scn].size(); j<sz; ++j){
		int vtx = info[scn][j].vertex;
		if(isScanned(vtx)) continue;
		int wgh = info[scn][j].weight;

		result[vtx] = result[vtx] > result[scn] + wgh ? (result[scn] + wgh) : result[vtx];
		candidates[vtx] = result[vtx];
	}

	int minimum=0xfffffff;
	for(int i=0; i<n; ++i){
		if(candidates[i]==-1) continue;
		nextvtx = minimum<candidates[i]? nextvtx : i;
		minimum = result[nextvtx];
	}
	candidates[nextvtx]=-1;
	scanned.push_back(nextvtx);
	return 0;
}

int main()
{
	scanf("%d",&n);
	scanned.reserve(n);
	info = new vector<Wside> [n];
	result = new int [n];
	candidates = new int [n];
	for(int i=0; i<n; ++i){
		result[i] = 0xfffffff;
		candidates[i] = -1;
	}

	int org,k,v,c;
	for(int i=0; i<n; ++i){
		scanf("%d %d",&org,&k);
		info[org].reserve(k);
		for(int j=0; j<k; ++j){
			scanf("%d %d",&v,&c);
			info[org].push_back(Wside(v,c));
		}
	}

	scanned.push_back(0);
	result[0] = 0;
	while(scanned.size()!=n){
		scan();
	}

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

	delete[] info;
	delete[] result;
	delete[] candidates;

	return 0;
}

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