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++: #include<iostream>
#include<vector>
#include<queue>
#include<utility>
#include<climits>
#include<algorithm>
using namespace std;
typedef int Cost;
typedef int Node;

void dijkstra(int start,   vector<vector< pair<Node,Cost> > > m){
  vector<Cost> costs(m.size());
  bool visited[m.size()];

  fill(costs.begin(),costs.end(),INT_MAX);
  fill(visited,visited+m.size(),false);
  
  priority_queue<pair<Cost,Node> ,vector<pair<Cost,Node> >, greater<pair<Cost,Node> > > q;
  q.push(make_pair(0,start));
  while(!q.empty()){
    Cost c = q.top().first;
    Node n = q.top().second;
    q.pop();
    if(!visited[n]){
      costs[n] = c;
      for(auto &x:m[n]){
        int node = x.first;
        int cost = x.second;
        q.push(make_pair(cost+c,node));
      }
      visited[n] = true;
    }
  }
  for(int i = 0;i < costs.size();i++){
    cout << i << ' ' << costs[i] << endl;
  }
}

int main(){
  int n;
  cin >> n;
  vector<vector< pair<Node,Cost> > > m(n);
  
  for(int i = 0;i < n;i++){
    int u,k;
    cin >> u >> k;
    for(int j = 0;j < k;j++){
      int v,c;
      cin >> v >> c;
      m[u].push_back(make_pair(v,c));
    }
  }
  dijkstra(0,m);
}

C++: #include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
static const int MAX=10000;
static const int INF=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(){
	int color[n];
	int d[n];
	for(int i=0;i<n;i++){
		color[i]=WHITE;
		d[i]=INF;
	}

	d[0]=0;
	priority_queue<pair<int,int> > pq;
	pq.push(make_pair(0,0));
	
	while(!pq.empty()){
		pair<int,int> f=pq.top();pq.pop();
		int u=f.second;
		color[u]=BLACK;
		
		int size=adj[u].size();
		for(int j=0;j<size;j++){
			int v=adj[u][j].first;
			if(color[v]==BLACK) continue;
			int w=adj[u][j].second;
			if(d[v]>d[u]+w){
				d[v]=d[u]+w;
				pq.push(make_pair(d[v]*-1,v));
			}
		}
	}

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

int main(){
	cin >> n;
	for(int i=0;i<n;i++){
		int u,k;
		cin >> u >> k;
		for(int j=0;j<k;j++){
			int v,c;
			cin >> v >> c;
			pair<int,int> p;
			p=make_pair(v,c);
			adj[u].push_back(p);
		}
	}
	dijkstra();
    return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>
using namespace std;
typedef  long long int lint;
//typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
#define mp make_pair
#define P pair<int,int>

int main() {
	int INF = 100000000;
	int V;
	cin >> V;
	vector<vector<P>>G(V);
	rep(i, V) {
		int v, k;
		cin >> v >> k;
		rep(j, k) {
			int tmpv, tmpc;
			cin >> tmpv >> tmpc;
			G[i].push_back(mp(tmpv, tmpc));
		}
	}
	int start = 0;//スタート位置
	vector<int>dist(V, INF);//startからの距離を入れる配列。INF(未訪問)で初期化
	dist[start] = 0;
	priority_queue<P, vector<P>, greater<P>>que;//少ない値を優先するプライオリティキューを宣言
	que.push(mp(dist[start], start));

	while (!que.empty()) {
		P p = que.top();
		int v = p.second;
		que.pop();
		if (dist[v] < p.first)continue;
		for (int i = 0; i < G[v].size(); i++) {
			P e = G[v][i];
			int u = e.first, cst = e.second;
			if (dist[u] > dist[v] + cst) {
				dist[u] = dist[v] + cst;
				que.push(mp(dist[u], u));
			}
		}
	}
	rep(i, V) {
		cout << i << ' ' << dist[i] << endl;
	}
}

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

typedef pair<int, int> node;
typedef vector<node> Adj_list;
typedef vector<Adj_list> Adj_lists;

class less_cost{
public:
  bool operator()(const pair<int, int> lhs, const pair<int, int> rhs) const{
    return lhs.second < rhs.second;
  }
};

int main(){

  int n;
  scanf("%d", &n);

  Adj_lists adj_lists(n);

  // read weigts
  for(int i=0; i<n; i++){
    int u, k;
    scanf("%d %d", &u, &k);
    for(int j=0; j<k; j++){
      int v,c;
      scanf("%d %d", &v, &c);
      adj_lists.at(u).push_back(node(v, c));
    }
  }

  // initialize cost
  vector<int> d(n, INT_MAX);
  d.at(0) = 0;
  priority_queue<node, vector<node>, less_cost> pq;
  pq.push(node(0, d.at(0)));

  //dijkstra's algorithm
  while(!pq.empty()){
    // extract node u in V-S that has minimum cost
    const node u = pq.top();
    pq.pop();

    // if u's cost is larger than d[u],
    // than ignore this one
    if(u.second < d.at(u.first)) continue;

    // update node in V-S and adjacent to u
    for(const node& v : adj_lists.at(u.first)){
      if(d.at(u.first) + v.second < d.at(v.first)){
        d.at(v.first) = d.at(u.first) + v.second;
        pq.push(node(v.first, d.at(v.first)));
      }
    }
  }

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

  return 0;
}