Go: package main

import (
	"fmt"
	"container/heap"
)

type Node struct {
	Id int
	Dis int
}

type PriorityQueue []*Node

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].Dis < pq[j].Dis
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *PriorityQueue) Push(x interface{}) {
	*pq = append(*pq, x.(*Node))
}

func (pq *PriorityQueue) Pop() interface{} {
	n := len(*pq)
	pop := (*pq)[n-1]
	*pq = (*pq)[0:n-1]
	return pop
}

func main() {
	var n int
	fmt.Scan(&n)

	g := make([][]int, n)
	c := make([][]int, n)
	pq := make(PriorityQueue, 0, n)
	d := make([]int, n)
	for i := 0; i < n; i++ {
		var u,k int
		fmt.Scan(&u)
		fmt.Scan(&k)
		g[u] = make([]int, k)
		c[u] = make([]int, k)
		for j := 0; j < k; j++ {
			fmt.Scan(&g[u][j])
			fmt.Scan(&c[u][j])
		}

		if u == 0 {
			d[u] = 0
		} else {
			d[u] = 1 << 30
		}
		pq.Push(&Node{u, d[u]})
	}
	heap.Init(&pq)

	for pq.Len() > 0 {
		node := heap.Pop(&pq).(*Node)
		for i := 0; i < len(g[node.Id]); i++ {
			nextId := g[node.Id][i]
			nextDis := node.Dis + c[node.Id][i]
			if nextDis < d[nextId] {
				d[nextId] = nextDis
				heap.Push(&pq, &Node{nextId, nextDis})
			}
		}
	}

	for i := 0; i < n; i++ {
		fmt.Println(i, d[i])
	}
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#define MAX 101
#define INF 1000001
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;

	vector<pair<int, int>>::iterator itv;

	for (itv = ver[0].begin(); itv != ver[0].end(); itv++) {
		dist[itv->first] = itv->second;
	}

}

void dijkstra(void) {
	int i, minu, 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;
			}
		}
	}
	isSelected[minu] = 1;
	//dist[minu] = dist[minp] + mindist;
	for (itv = ver[minu].begin(); itv != ver[minu].end(); itv++) {
		if (isSelected[itv->first] == 1)continue;
		dist[itv->first] = min(dist[minu] + itv->second, dist[itv->first]);
	}
}

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

C++: #include <bits/stdc++.h>
using namespace std;

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

struct edge { int to, cost; };
using P = pair<int, int>;

const int INF = 1e8;
int n;
vec<vec<edge>> G;
int d[111];

void dijkstra(int s) {
   priority_queue<P, vec<P>, greater<P>> Q;
   fill(d, d + n, INF);
   d[s] = 0;
   Q.push({0, s});

   while (Q.size()) {
      P p = Q.top(); Q.pop();
      int v = p.second;
      if (d[v] < p.first) continue;
      for (int i = 0; i < G[v].size(); i++) {
         edge e = G[v][i];
         if (d[e.to] > d[v] + e.cost) {
            d[e.to] = d[v] + e.cost;
            Q.push({d[e.to], e.to});
         }
      }
   }
}

int main() {
   cin >> n;
   G = vec<vec<edge>>(n);
   rep (i, n) {
      int u, k;
      cin >> u >> k;
      rep (j, k) {
         int v, c;
         cin >> v >> c;
         G[u].push_back({v, c});
      }
   }

   dijkstra(0);

   rep (i, n) {
      printf("%d %d\n", i, d[i]);
   }

   return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int inf = 1<<29;
int n;
vector<pair<int, int>> G[110];
vector<int> d(110, inf);

void dijkstra(int s){
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> qu;
    d[s] = 0;
    qu.push(make_pair(0, s));

    while(!qu.empty()){
        pair<int, int> p = qu.top(); qu.pop();
        if(d[p.second] < p.first) continue;
        for(auto e:G[p.second]){
            if(d[e.second] > p.first+e.first){
                d[e.second] = p.first+e.first;
                qu.push(make_pair(d[e.second], e.second));
            }
        }
    }
}

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

    dijkstra(0);
    for(int i=0; i<n; ++i){
        cout << i << ' ' << d[i] << '\n';
    }

    return 0;

}

C++: #include <iostream>
#include <vector>

using WNode = std::pair<uint32_t, uint32_t>;
using WGraph = std::vector<std::vector<WNode>>;

int main() {
  uint32_t N = 0;
  std::cin >> N;
  WGraph G(N);
  for (size_t i = 0; i < N; i++) {
    uint32_t K = 0;
    std::cin >> i >> K;
    for (size_t j = 0; j < K; j++) {
      uint32_t node = 0, cost = 0;
      std::cin >> node >> cost;
      G[i].push_back({node, cost});
    }
  }

  const uint32_t start = 0;
  std::vector<uint32_t> min_cost(N, -1);
  min_cost[start] = 0;
  std::vector<uint32_t> prev_node(N, -1);
  prev_node[start] = start;
  std::vector<bool> visit(N, false);
  for (size_t i = 0; i < N; i++) {
    uint32_t current = 0, min = -1;
    for (size_t j = 0; j < N; j++) {
      if (visit[j] || min_cost[j] >= min) continue;
      min = min_cost[j];
      current = j;
    }
    visit[current] = true;

    for (auto &&g : G[current]) {
      if (min_cost[g.first] <= g.second + min_cost[current]) continue;
      min_cost[g.first] = g.second + min_cost[current];
      prev_node[g.first] = current;
    }
  }

  for (size_t i = 0; i < N; i++) {
    std::cout << i << " " << min_cost[i] << std::endl;
  }

  return 0;
}