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++: import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    int[] distTo = null;
    int[] parentOf = null;

    public Main(ArrayList<ArrayList<Edge>> G){
        distTo = new int[G.size()];
        Arrays.fill(distTo, Integer.MAX_VALUE);
        parentOf = new int[G.size()];

        PriorityQueue<SDto> pq = new PriorityQueue<>();

        pq.add(new SDto(0, 0, -1));
        while (!pq.isEmpty()) {

            SDto optim = pq.poll();

            if (optim.d < distTo[optim.v]) {
                distTo[optim.v] = optim.d;
                parentOf[optim.v] = optim.from;
                for (Edge e : G.get(optim.v)) {
                    if (optim.from != e.v) { // prevent go back
                        pq.add(new SDto(e.v, distTo[optim.v] + e.c, optim.v));
                    }
                }

            }
        }

    }

    private static class SDto implements Comparable<SDto> { // Shortest distance to vertex
        int v, d, from;

        SDto(int v, int d, int from) {
            this.v = v;
            this.d = d;
            this.from = from;
        }

        @Override
        public int compareTo(SDto that) {
            if(this.d > that.d) return 1;
            else if(this.d < that.d) return -1;
            return 0;
        }


    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();

        ArrayList<ArrayList<Edge>> G = new ArrayList<>(n);
        for (int i = 0; i < n; i++) {
            G.add(new ArrayList<>());
        }

        for (int i = 0; i < n; i++) {
            int u = in.nextInt();
            int k = in.nextInt();
            for (int j = 0; j < k; j++) {
                int v = in.nextInt(), c = in.nextInt();
                G.get(i).add(new Edge(v, c));
                G.get(v).add(new Edge(i, c));
            }
        }

        Main dijkstra = new Main(G);

        for (int i = 0; i < G.size(); i++) {
            System.out.printf("%d %d\n", i, dijkstra.distTo[i]);
        }
    }
}

class Edge {
    int v, c;

    Edge(int v, int c) {
        this.v = v;
        this.c = c;
    }

    @Override
    public String toString() {
        return String.format("(v=%d, c=%d)", v, c);
    }
}

C++: #include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n + 1); ++i)
using namespace std;
using ll = long long;
const int INF = +100100100;
// typedef pair<int,int> P;
const int  WHITE = 0;
const int GRAY =1;
const int BLACK =2;
const int NIL = -1;
const int MAX = 100;

// 配列のサイズを大きく取りすぎるとエラーが出ないが、実行できなくなる.
vector<vector<int>> M(MAX,vector<int>(MAX,INF));
vector<int> color(MAX,WHITE), P(MAX,NIL),D(MAX,INF);
int n;

void dijkstra(){
    int u = 0;
    D[u] = 0;
    while(1){
        int mini =INF;
        rep(i,n){
            if(mini>D[i] && color[i]!=BLACK){
                u = i;
                mini = D[i];
            }
        }
        if(mini==INF)break;
        color[u]=BLACK;
        rep(i,n){
            if(color[i]==BLACK)continue;
            if(D[u]+M[u][i]<D[i]){
                D[i] = D[u]+M[u][i];
            }
            color[i]=GRAY;
        }

    }
}

int main(){
    cin >> n;
    rep(i,n){
        int id, m;
        cin >> id>>m;
        rep(j,m){
            int opp;cin>>opp;
            int cost; cin >> cost;
            M[i][opp]=cost;
        }
    }
    dijkstra();
    rep(i,n){
        cout<<i << " " << D[i]<<endl;
    }
    return 0;
}

C++: #include<stdio.h>
#include<algorithm>
#define  INF  1e9 
using namespace std;
typedef long long ll;
ll q[210][210];
int  p[210];
ll  dis[210];

void Dijkstra(int N){
	fill(dis,dis+210,INF);
	dis[0]=0;
	int x=0;
	while(p[N-1]==0){
		ll mini=INF;
		p[x]=1;
		for(int y=0;y<N;y++){
			if(p[y]==1)  continue;
			dis[y]=min(dis[y],dis[x]+q[x][y]);
		}
		for(int i=0;i<N;i++){
			if(p[i]==1) continue;
			if(mini>dis[i]){
				mini=dis[i];
				x=i;
			}
		}
	}
}
 
int main()
{
    int u,N,k,v;
	ll C;
	while(~scanf("%d",&N))
	{
		fill(q[0],q[0]+210*210,INF);
		fill(p,p+210,0);
		int M=N;
		while(N--)
		{
		    scanf("%d%d%",&u,&k);
		    for(int i=0;i<k;i++){
		    	scanf("%d%lld",&v,&C);
                q[u][v]=min(q[u][v],C);
			}
		}
		Dijkstra(M);
		for(int i=0;i<M;i++){
			printf("%d %lld\n",i,dis[i]);
		}
	}
	return 0;
}