Go: package main

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

//make priority queue
type Item struct {
	id       int
	priority int // this state is priority and distans from start
	index    int
}

type PriorityQueue []*Item

func (pq PriorityQueue) Len() int { return len(pq) }

// we want the ascending-priority-queue.
// So we use less than here.
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 = j
	pq[j].index = i
}

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
}

func (pq *PriorityQueue) update(dist int, id int) {
	for _, i := range *pq {
		if i.id == id {
			if i.priority > dist {
				i.priority = dist
			}
		}
	}
}

// the main code
func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

func dikstra(dist [][]int, n int) []int {
	// preparate priority queue
	inf := 1 << 30
	pq := make(PriorityQueue, n)
	shortests := make([]int, n)
	for i := 0; i < n; i++ {
		pq[i] = &Item{
			id:       i,
			priority: inf,
			index:    i,
		}

		shortests[i] = inf
	}
	pq[0].priority = 0
	shortests[0] = 0
	heap.Init(&pq)

	for pq.Len() > 0 {
		item := heap.Pop(&pq).(*Item)
		shortests[item.id] = item.priority
		for id, d := range dist[item.id] {
			if d != -1 {
				pq.update(item.priority+d, id)
			}
		}
		heap.Init(&pq)
	}
	return shortests
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	// init
	n := nextInt(sc)
	dist := make([][]int, n)
	for i := 0; i < n; i++ {
		dist[i] = make([]int, n)
		for j := 0; j < n; j++ {
			dist[i][j] = -1
		}
	}

	// std Input
	for i := 0; i < n; i++ {
		u := nextInt(sc)
		k := nextInt(sc)
		for j := 0; j < k; j++ {
			v, c := nextInt(sc), nextInt(sc)
			dist[u][v] = c
		}
	}

	shortests := dikstra(dist, n)
	for i, d := range shortests {
		fmt.Printf("%d %d\n", i, 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;
}