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 <bits/stdc++.h>



using namespace std;



static const int INF = 999999;



int main(){

	int n,array[100][100];



	for(int i=0; i<100; i++){

		for(int j=0; j<100; j++){

			if(i==j) array[i][j]=0;

			else array[i][j]=INF;

		}

	}

	

	cin>>n;



	for(int i=0; i<n; i++){

		int u,k;

		cin>>u>>k;

		for(int j=0; j<k; j++){

			int t,c;

			cin>>t>>c;

			array[u][t]=array[t][u]=c;

		}

	}



	int d[100];

	fill(d,d+n,INF);

	d[0]=0;

	bool flag[100]={};



	while(1){

		int u=-1,infn=INF;

		for(int i=0; i<n; i++){

			if(!flag[i] && d[i]<=infn){

				u = i;

				infn = d[u];

			}

		}

		if(u==-1) break;

		flag[u] = true;



		for(int i=0; i<n; i++){

			if(array[u][i]!=INF && !flag[i]){

				d[i] = min(d[i],d[u]+array[u][i]);

			}

		}

	}



	for(int i=0; i<n; i++){

		cout<<i<<" "<<d[i]<<endl;

	}



	return 0;

}

C++: #include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>

using namespace std;

#define MAX_N 100
#define INF 100001

int cost[MAX_N][MAX_N];
int d[MAX_N];
bool used[MAX_N];
int V;

void dijkstra(int s) {
	fill_n(d, V, INF);
	fill_n(used, V, false);
	d[s] = 0;

	while (1) {
		int v = -1;
		for (int u = 0; u < V; u++)
			if (!used[u] && (v == -1 || d[u] < d[v]))
				v = u;

		if (v == -1)
			break;

		used[v] = true;

		for (int u = 0; u < V; u++)
			d[u] = min(d[u], d[v] + cost[v][u]);
	}
}

int main() {
	int n;
	cin >> n;
	V = n;
	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		fill_n(cost[u], n, INF);
		for (int j = 0; j < k; j++) {
			int v, c;
			cin >> v >> c;
			cost[u][v] = c;
		}
	}
	dijkstra(0);
	for (int i = 0; i < n; i++) {
		cout << i << " " << d[i] << endl;
	}
	
	return 0;
}

C++: //By Vlgd
#include<bits/stdc++.h>
using namespace std;
const int INF=(1<<21);
const int N=100;
int G[N][N],n,vis[N]={0},dis[N];
void dij(int s){
	dis[s]=0;
	while(1){
		int min=INF,u=-1;
		for(int i=0;i<n;i++){
			if(!vis[i]&&min>dis[i]){
				min=dis[i];
				u=i;
			} 
		}
		if(u==-1) break;
		vis[u]=1;
		for(int v=0;v<n;v++)
			if(G[u][v]!=INF&&!vis[v])
				if(dis[v]>dis[u]+G[u][v]) 
					dis[v]=dis[u]+G[u][v];
	}
}
int main(){
	scanf("%d",&n);
	int u,v,deg,w;
	for (int i=0;i<n;i++){
		dis[i]=INF;
		for (int j=0;j<n;j++) G[i][j]=INF;
	}
	for (int i=0;i<n;i++){
		scanf("%d%d",&u,&deg);
		for (int j=0;j<deg;j++){scanf("%d%d",&v,&w);G[u][v]=w;}
	}
	dij(0);
	for (int i=0;i<n;i++) printf("%d %d\n",i,dis[i]);
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>

#define INF 2000000001
#define MAX 101
#define NIL -1

using namespace std;

typedef struct {
    int toid;
    int far;
} PATH;

vector<PATH> D[MAX];
int N;
int Dist[MAX];

void dijkstra(){//0??????????????¢??????????????£?????????
    
    bool complete[MAX];
    vector<int> S;
    
    for (int i = 0; i < N; i++) {
        complete[i] = false;
        Dist[i] = INF;
    }
 
    //???????¨????
    Dist[0] = 0;
    S.push_back(0);
    int u=0,minf;
    complete[u] = true;
    
    while (1) {
        if (S.size() == N) break;
        
        //????????????
        for (int j = 0; j < D[S[u]].size(); j++) {
            if (!complete[D[S[u]][j].toid] && Dist[S[u]] + D[S[u]][j].far < Dist[D[S[u]][j].toid]) {
                Dist[D[S[u]][j].toid] = Dist[S[u]] + D[S[u]][j].far;
            }
        }
        
        
        
        u = NIL;
        minf = INF;
        
        //?¨??????´??°
        for (int i = 0; i < S.size(); i++) {
            
            for (int j = 0; j < D[S[i]].size(); j++) {
                if (Dist[D[S[i]][j].toid] < minf && !complete[D[S[i]][j].toid]) {
                    minf = Dist[D[S[i]][j].toid];
                    u = D[S[i]][j].toid;
                }
            }
            
        }
        S.push_back(u);
        complete[u] = true;
        u = S.size()-1;//????????§u????????§??¨????????????????????????
    }
}

int main(){
    cin >> N;
    for (int i = 0; i < N; i++) {
        int bb1,bb2;
        cin >> bb1 >> bb2;
        for (int j = 0; j < bb2; j++) {
            PATH bb3;
            cin >> bb3.toid >> bb3.far;
            D[i].push_back(bb3);
        }
    }
    
    dijkstra();
    
    for (int i = 0; i < N; i++) {
        printf("%d %d\n",i,Dist[i]);
    }
    
    return 0;
}