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 <cstdio>
#include <algorithm>
#include <queue>
using namespace std;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;
vector<pair<int, int>> adj[100];
int *d;

void dijkstra() {
    priority_queue<pair<int, int>> PQ;
    int d[n], color[n];

    for (int i = 0; i < n; i++) {
        d[i] = INFTY;
        color[n] = WHITE;
    }
    d[0] = 0;
    PQ.push(make_pair(0, 0));

    while (!PQ.empty()) {
        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[u] + adj[u][j].second < d[v]) {
                d[v] = d[u] + adj[u][j].second;
                // printf("d[%d] = %d\n", v, d[v]);
                PQ.push(make_pair(d[v] * (-1), v));
                color[v] = GRAY;
            }
        }
    }
    
    for (int i = 0; i < n; i++) {
        printf("%d %d\n", i, d[i]);
    }
}

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

    // adj = new vector<pair<int, int>>[n];

    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[u].push_back(make_pair(v, c));
        }
    }

    dijkstra();

    return 0;
}

C++: #include<iostream>
#include<queue>
#include<utility>
#include<stdio.h>
using namespace std;
typedef pair<int,int> P;
int main(){
  const int INF=(1<<29);
  int min[1010],fix[1010];
  int map[1010][1010];
  int s1; 
  int n,m,i,j,x,y,z,count=0; 
  priority_queue<P,vector<P>,greater<P> > que; 
  scanf("%d\n",&n);
  for(i=0;i<=n;i++){
    min[i]=INF,fix[i]=0;
  }
  for(i=0;i<=n;i++){
    for(j=0;j<=n;j++){
      map[i][j]=-1;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&x,&m);
    for(j=0;j<m;j++){
      scanf("%d %d",&y,&z);
    if(map[x][y]==-1 || map[x][y]>z){
    map[x][y]=z;
    }
    }
    scanf("\n");
  }
  s1=0;
  que.push(P(0,s1));
  min[s1]=0;
  while(!que.empty()){
    P p=que.top();
    que.pop();
    int v=p.second;
    if(min[v]<p.first){
      continue;
    }
    for(i=0;i<=n;i++){
      if(map[v][i]!=-1 && min[i]>min[v]+map[v][i] && fix[i]==0){
        min[i]=min[v]+map[v][i];
        que.push(P(min[v]+map[v][i],i));
      }
    }
    fix[v]=1;
  }
  for(i=0;i<n;i++){
  printf("%d %d\n",i,min[i]);
  }
  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<climits>
#include<cstring>
#define INF INT_MAX
using namespace std;
typedef unsigned long long ull;
int n;
int A[1000][1000];
ull D[1000][1000];
 
void Init(int f){
  for(int i=0;i<=f+50;i++){
    for(int j=0;j<=f+50;j++)D[i][j] = INF;
  }
 
}
 
int main(){
  scanf("%d",&n);
  int u,k,C,V;
  Init(n);
  
  for(int i=0;i<n;i++){
    scanf("%d %d",&u,&k);    
    for(int j=0;j<k;j++){
      scanf("%d %d",&V,&C);
      D[u][V] = C;
      D[V][u] = C;
    }    
  }
  
  for(int i=0;i<n;i++)D[i][i] = 0;
  for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++)D[i][j] = min(D[i][j],D[i][k] + D[k][j]);
  for(int i=0;i<n;i++){
    cout << i << " " << D[0][i] << endl;
  }
 
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <queue>
#define INF 1000000
using namespace std;

class vertex{
public:
  class edge{
  public:
    int to;
    int weight;
    edge(int to, int weight){
      this->to = to;
      this->weight = weight;
    }
  };

  vector<edge> edges;
  int num;
  int dis;

  vertex(){
    n++;
    vertexes.push_back(this);
  }

  bool operator< (const vertex& v) const{
    return dis < v.dis;
  }

  bool operator> (const vertex& v) const{
    return dis > v.dis;
  }

  static void dijkstra(int start){
    //距離の初期化
    for(int i=0; i<n; i++) vertexes[i]->dis=INF;
    vertexes[start]->dis=0;

    //プライオリティキューを初期化、始点を格納
    priority_queue<vertex, vector<vertex>, greater<vertex> > pq; pq.push(*vertexes[start]);


    while(!pq.empty()){
      vertex now = pq.top(); pq.pop(); //キューの先頭をポップ
      if(now.dis>vertexes[now.num]->dis) continue;

      //ポップしたキューの頂点集合について最短距離更新
      for(int i=0; i<now.edges.size(); i++){
        int newDis = now.dis+now.edges[i].weight;
        vertex* next = vertexes[now.edges[i].to];
        if(newDis < next->dis){
          next->dis = newDis;
          pq.push(*next);
        }
      }

    }


  }

  static void print(){
    for(int i=0; i<n; i++){
      cout << vertexes[i]->num << " " << vertexes[i]->dis << endl;
    }
  }
private:
  static int n;
  static vector<vertex*> vertexes;
};

int vertex::n=0;
vector<vertex*> vertex::vertexes;

int main(){
  int n; cin >> n;

  vertex graph[n];

  //入力を隣接リストのようなものに格納
  int v, k, to, weight;
  for(int i=0; i<n; i++){
    cin >> v >> k;
    graph[i].num=v;
    for(int j=0; j<k; j++){
      cin >> to >> weight;
      vertex::edge e(to, weight);
      graph[v].edges.push_back(e);
    }
  }

  vertex::dijkstra(0); //0始点のダイクストラ法

  vertex::print();

  return 0;
}