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 <bits/stdc++.h>
#define REP(i, a, b) for(int i = (a); i < (b); i++)
#define RREP(i, a, b) for(int i = (a); i >= (b); i--)
#define pq priority_queue
#define P pair<int, int>
#define P2 pair<int, P>
#define P3 pair<int, P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF = 1e9, MOD = 1e9+7, around[] = {0, 1, 1, -1, -1, 0, -1, 1, 0, 0};
const int vx[] = {1, 0, -1, 0}, vy[] = {0, 1, 0, -1};
const ld PI = abs(acos(-1));
const int sqrtN = 512;
const int logN = 32;
const ll LINF=1e18;

template<typename T>
struct Dijkstra{
	struct edge{
		int to;
		T cost;
	};
	const T INF;
	vector<vector<edge>> g;
	vector<T> min_cost;
	
	Dijkstra(int n) : INF(numeric_limits<T>::max()){
		g.resize(n);
	}
	
	void add_edge(int from, int to, T cost){
		g[from].push_back(edge{to, cost});
	}
	
	vector<T> dijkstra(int s){
		min_cost.assign(g.size(), INF); min_cost[s] = 0;
		pq<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> qu;
		qu.push({0, s});
		
		while(!qu.empty()){
			auto p = qu.top(); qu.pop();
			
			for(auto e:g[p.second]){
				if(p.first + e.cost >= min_cost[e.to]) continue;
				min_cost[e.to] = p.first + e.cost;
				qu.push({min_cost[e.to], e.to});
			}
		}
		
		return min_cost;
	}
};


int main(){
	int n; cin >> n;
	Dijkstra<ll> dijk(n);
	for(int i = 0; i < n; i++){
		int k; cin >> k >> k;
		
		for(int j = 0; j < k; j++){
			int a, b; cin >> a >> b;
			dijk.add_edge(i, a, (ll)b);
			dijk.add_edge(a, i, (ll)b);
		}
	}
	
	vector<ll> min_cost = dijk.dijkstra(0);
	for(int i = 0; i < n; i++) cout << i << " " << min_cost[i] << endl;
	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
const int inf=0x3f3f3f3f;
const int maxn=109;
int map1[maxn][maxn];
int flag[maxn];
int vis[maxn];
int c[maxn];

void spfa(int u,int n){
    queue<int>q;
    memset(flag,0,sizeof(flag));
    memset(c,0,sizeof(c));
    for(int i=0;i<n;i++)
        vis[i]=inf;
    vis[0]=0;c[0]=1,flag[0]=1;
    q.push(0);
    while(!q.empty()){
        int now=q.front();
        q.pop();
        flag[now]=0;
        for(int i=0;i<n;i++){
            if(vis[i]>vis[now]+map1[now][i]){
                vis[i]=vis[now]+map1[now][i];
                if(!flag[i]){
                    flag[i]=1;
                    q.push(i);
                }

            }
        }
    }
}

int main(){
    int n,u,v,w,k;
    while(scanf("%d",&n)!=EOF){
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
                if(i==j)
                    map1[i][j]=0;
                else
                    map1[i][j]=inf;
        for(int i=0;i<n;i++){
            scanf("%d%d",&u,&k);
            for(int j=0;j<k;j++){
                scanf("%d%d",&v,&w);
                if(map1[u][v]>w)
                    map1[u][v]=w;
            }
        }
        spfa(0,n);
        for(int i=0;i<n;i++)
            printf("%d %d\n",i,vis[i]);
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#define INF 1<<30
using namespace std;
int main() {
	cin.tie(0);ios::sync_with_stdio(false);
	int V; cin >> V;
	vector<vector<pair<int, int>>> g(V);
	vector<int> dp(V);
	queue<int> q;

	//input
	for (int i = 0; i < V; i++) {
		int u, k; cin >> u >> k;
		for (int j = 0; j < k; j++) {
			int c, v;
			cin >> c >> v;
			g[u].push_back(make_pair(c, v));
		}
	}

	//initialize
	fill(dp.begin(), dp.end(), INF);
	dp[0] = 0;
	q.push(0);

	//Dijkstra
	while (!q.empty()) {
		int k = q.front(); q.pop();
		for (int i = 0; i < g[k].size();i++) {
			int next = g[k][i].first;
			int w = g[k][i].second;
			if (dp[k] + w < dp[next]) {
				dp[next] = dp[k] + w;
				q.push(next);
			}
		}
	}

	//output
	for (int i = 0; i < V;i++) {
		cout << i << " " << dp[i] << endl;
	}
}

C++: #include <cstdio>
#include <algorithm>
#include <queue>
#include <utility>
#include <unordered_map>
#include <vector>

using edge = std::pair<int, int>;
#define N 100

int main(){
    int n;
    std::scanf("%d", &n);
    std::vector<edge> a[N];
    for(int i = 0; i < n; ++i){
        int id;
        int num;
        std::scanf("%d", &id);
        std::scanf("%d", &num);
        for(int j = 0; j < num; ++j){
            edge e;
            std::scanf("%d", &e.second);//id                                                                                                                                                                                        
            std::scanf("%d", &e.first);//weight                                                                                                                                                                                     
            a[id].push_back(e);
        }
    }
    std::priority_queue<edge, std::vector<edge>, std::greater<edge> > que;
    std::unordered_map<int, int> checked;
    checked.insert(std::make_pair(0, 0));
    for(auto &x: a[0]){
        que.push(x);
    }
    while(checked.size() != n){
        while(checked.find(que.top().second) != checked.end()){
            que.pop();
        }
        edge e = que.top();
        que.pop();
        checked.insert(std::make_pair(e.second, e.first));
        for(auto &x: a[e.second]){
            if(checked.find(x.second) == checked.end()){
                x.first += e.first;
                que.push(x);
            }
        }
    }

    for(int i = 0; i < n; ++i){
        auto x = checked.find(i);
        std::printf("%d %d\n", x->first, x->second);
    }

    return 0;
}