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>
using namespace std;
const int MAXN = 100+7;
const int INF = 1e6+7;
int m[MAXN][MAXN];
int d[MAXN];
bool visit[MAXN];
int n;
set<int> s;
void djas()
{
    d[0] = 0;
    for(int i = 1; i < n; i++)
    {
        d[i] = INF;
    }
    while(s.size() != n)
    {
        int min_d = INF;
        int s1;
        for(int j = 0; j < n; j++)
        {
            if(d[j]<min_d && visit[j]==false)
            {
                min_d = d[j];
                s1 = j;
            }
        }

        s.insert(s1);
        visit[s1] = true;
        for(int j = 1; j < n; j++)
        {
            if(m[s1][j]!=-1 && d[s1]+m[s1][j]<d[j] && j!=s1 && visit[j]==false){
                d[j] = d[s1]+m[s1][j];
            }
        }
    }
}
int main()
{
//    freopen("in.txt", "r", stdin);
    memset(visit, false, sizeof(visit));
    memset(m, -1, sizeof(m));
    scanf("%d", &n);
    for(int i = 0; i < n; i++)
    {
        int id;
        scanf("%d", &id);
        int degree;
        scanf("%d", &degree);
        for(int j = 0; j < degree; j++)
        {
            int v;
            scanf("%d", &v);
            int c;
            scanf("%d", &c);
            m[id][v] = c;
        }
    }
    djas();
    for(int i = 0; i < n; i++)
    {
        printf("%d %d\n", i, d[i]);
    }

    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

#define Vi vector<int>
#define FOR(i,s,e) for (int i=s; i<e; i++)
#define ITER(v) v.begin(), v.end()

constexpr int N_MAX = 100;

int weight[N_MAX][N_MAX];
int dis[N_MAX];

void exhaust_search(const int cur, const int d, const int n, std::array<bool, N_MAX> isvisited) {
    isvisited[cur] = true;
    if (dis[cur] < 0 || d < dis[cur]) { dis[cur] = d; }
    for (int next = 0; next < n; ++next) {
        if (isvisited[next]) { continue; }
        if (weight[cur][next] < 0) { continue; }
        exhaust_search(next, d + weight[cur][next], n, isvisited);
    }
}

void set_shortest_distance(const int n) {
    std::array<bool, N_MAX> isvisited;
    isvisited.fill(false);
    exhaust_search(0, 0, n, isvisited);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    FOR(i,0,n) {
        dis[i] = -1;
        FOR(j,0,n) {
            weight[i][j] = -1;
        }
    }

    int u, k, v, c;
    FOR(i,0,n) {
        cin >> u >> k;
        FOR(j,0,k) {
            cin >> v >> c;
            weight[u][v] = c;
        }
    }

    set_shortest_distance(n);

    for (int i = 0; i < n; ++i) {
        cout << i << " " << dis[i] << endl;
    }

    return 0;
}

C++: #include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main() {
	int n, u, k, v, c, i, j, d[100][100], m[100][100], o, p[100] = { 0 }, e, q = 0;
	memset(m, 0x7f, sizeof(m));
	memset(d, 0x7f, sizeof(d));
	d[0][0] = 0;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> u >> k;
		for (j = 0; j < k; j++) {
			cin >> v >> c;
			m[u][v] = c;
		}
	}
	p[0] = 1;
	for (i = 1; i < n; i++) {
		o = d[0][n - 1];
		for (j = 0; j < n; j++) {
			d[i][j] = min(d[i][j], m[q][j] + d[i - 1][q]);
			d[i][j] = min(d[i][j], d[i - 1][j]);
			if (o >= d[i][j] && p[j] == 0) {
				e = j;
				o = d[i][j];
			}
		}
		p[e] = 1;
		q = e;
	}
	for (i = 0; i < n; i++)cout << i << ' ' << d[n - 1][i] << endl;
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#define MAX 101
#define INF 100001
using namespace std;

int n, isSelected[MAX], dist[MAX];
vector<pair<int, int>> ver[MAX];

void initDijkstra(void);
void dijkstra(void);
bool doesFinished(void);

int main() {
	int i, j, id, k, v, c;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> id >> k;
		for (j = 0; j < k; j++) {
			cin >> v >> c;
			ver[id].push_back(make_pair(v, c));
		}
	}

	initDijkstra();

	while (!doesFinished())dijkstra();

	for (i = 0; i < n; i++) {
		cout << i << " " << dist[i] << endl;
	}

	return 0;
}

void initDijkstra(void) {
	dist[0] = 0;
	isSelected[0] = 1;
	for (int i = 1; i <= n; i++)dist[i] = INF;
}

void dijkstra(void) {
	int i, minu, minp, mindist = INF;
	vector<pair<int, int>>::iterator itv;
	for (i = 0; i < n; i++) {
		if (isSelected[i] == 0)continue;
		for (itv = ver[i].begin(); itv != ver[i].end(); itv++){
			if (isSelected[itv->first] == 1)continue;
			if (itv->second < mindist) {
				mindist = itv->second;
				minu = itv->first;
				minp = i;
			}
		}
	}
	isSelected[minu] = 1;
	dist[minu] = dist[minp] + mindist;
}

bool doesFinished(void) {
	for (int i = 0; i < n; i++) {
		if (isSelected[i] == 0)return false;
	}
	return true;
}