Go: package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	r := bufio.NewReader(os.Stdin)

	var n int
	fmt.Fscan(r, &n)
	cs := make([]map[int]int, n) // []v_i -> c_i
	for h := 0; h < n; h++ {
		var u, k int
		fmt.Fscan(r, &u, &k)
		m := make(map[int]int)
		for i := 0; i < k; i++ {
			var v, c int
			fmt.Fscan(r, &v, &c)
			m[v] = c
		}

		cs[u] = m
	}

	q := make(map[int]int)
	q[0] = 0
	visited := make(map[int]struct{})
	out := make([]int, n)

	for len(q) > 0 {
		u := top(q)
		for uu, c := range cs[u] {
			// Consider the connection between u and uu.
			if _, ok := visited[uu]; ok {
				continue
			}
			if d, ok := q[uu]; !ok || d > q[u]+c {
				q[uu] = q[u] + c
			}
		}

		out[u] = q[u]
		delete(q, u)
		visited[u] = struct{}{}
	}

	for u, d := range out {
		fmt.Println(u, d)
	}
}

func top(q map[int]int) int {
	minu := -1
	min := -1
	for u, d := range q {
		if min < 0 || d < min {
			minu = u
			min = d
		}
	}

	return minu
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <functional>

#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

typedef std::pair<int, int> P;

class Edge{
public:
	int to;
	int cost;

	Edge(){
		return;
	}
	~Edge(){
		return;
	}
};

int main(int argc, char **argv){
	std::vector<std::vector<Edge> >  G;
	std::vector<long> min_cost;
	std::priority_queue<P, std::vector<P>, std::greater<P> > que;

	int n, u, k, v, c;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	//FILE *fp = fopen("test.txt", "r");
#endif

	
#if INPUT_FROM_FILE
	ifs >> n;
#else
	std::cin >> n;
#endif
	G.resize(n);
	min_cost.resize(n, 1000000000) ;

	for(int i = 0; i < n; i++){
#if INPUT_FROM_FILE
		ifs >> u >> k;
#else
		std::cin >> u >> k;
#endif
		for(int j = 0; j < k; j++){
#if INPUT_FROM_FILE
			ifs >> v >> c;
#else
			std::cin >> v >> c;
#endif
			Edge e;
			e.to = v;
			e.cost = c;

			G[u].push_back(e);

		}
	}

	min_cost[0] = 0;
	que.push(P(0, 0));

	while(!que.empty()){
		P p = que.top(); que.pop();
		int v = p.second;

		if(min_cost[v] < p.first){ 
			continue;
		}

		for(int i = 0; i < G[v].size(); i++){
			Edge e = G[v][i];
			if(min_cost[e.to] > min_cost[v] + e.cost){
				min_cost[e.to] = min_cost[v] + e.cost;
				que.push(P(min_cost[e.to], e.to));
			}
		}
	}

	for(int i = 0; i < n; i++){
		std::cout << i << " " << min_cost[i] << std::endl;
	}
	return 0;
}

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

using namespace std;
using MatrixGraph = vector<vector<int>>;

const int infinity = numeric_limits<int>::max();
const int no_label = -1;

vector<int> calc_shortest_path(MatrixGraph matrix_graph, int started_label) {
  vector<int> min_costs(matrix_graph.size(), infinity);
  vector<bool> is_visits(matrix_graph.size(), false);

  min_costs[started_label] = 0;

  while(true) {
    int min_cost_adjacency_label = no_label;
    int min_cost_adjacency_weight = infinity;
    for(int i = 0; i < matrix_graph.size(); i++) {
      if(is_visits[i]) {
        continue;
      }

      if(min_costs[i] < min_cost_adjacency_weight) {
        min_cost_adjacency_label = i;
        min_cost_adjacency_weight = min_costs[i];
      }
    }
    if(min_cost_adjacency_label == no_label) {
      break;
    }

    is_visits[min_cost_adjacency_label] = true;

    for(int i = 0; i < matrix_graph.size(); i++) {
      if(matrix_graph[min_cost_adjacency_label][i] == infinity) {
        continue;
      }

      if(min_costs[min_cost_adjacency_label] + matrix_graph[min_cost_adjacency_label][i] < min_costs[i]) {
        min_costs[i] = min_costs[min_cost_adjacency_label] + matrix_graph[min_cost_adjacency_label][i];
      }
    }
  }

  return min_costs;
}

int main() {
  int vertex_num;
  cin >> vertex_num;
  MatrixGraph matrix_graph(vertex_num, vector<int>(vertex_num, infinity));

  for(int i = 0; i < vertex_num; i++) {
    int label, degree;
    cin >> label >> degree;
    for(int j = 0; j < degree; j++) {
      int adjacency_label;
      int adjacency_weight;
      cin >> adjacency_label >> adjacency_weight;
      matrix_graph[label][adjacency_label] = adjacency_weight;
    }
  }

  vector<int> min_consts = calc_shortest_path(matrix_graph, 0);

  for(int i = 0; i < min_consts.size(); i++) {
    cout << i << ' ' << min_consts[i] << endl;
  }
}

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

const int MAX=10005;
int state[MAX],N,D[MAX];
vector<pair<int,int>> S[MAX];
priority_queue<pair<int,int>> Q;

void dijkstra(){
    int cnt=1;
    for(int i=0;i<N;i++){
        state[i]=0;
        D[i]=10000000;
    }
    state[0]=1;
    D[0]=0;
    for(int i=0;i<S[0].size();i++){
        Q.push(make_pair(-S[0][i].second,S[0][i].first));
        D[S[0][i].first]=min(D[S[0][i].first],D[0]+S[0][i].second);
    }
    while(1){
        int a=Q.top().second;
            if(state[a]==0){
            Q.pop();
            state[a]=1;
            for(int i=0;i<S[a].size();i++){
                if(state[S[a][i].first]==0){
                    Q.push(make_pair(-(D[a]+S[a][i].second),S[a][i].first));
                    D[S[a][i].first]=min(D[S[a][i].first],D[a]+S[a][i].second);
                }
            }
                cnt++;
        }
        else Q.pop();
        if(cnt==N) break;
    }
    return;
}


int main(){
    
    cin>>N;
    for(int i=0;i<N;i++){
        int l,a;cin>>l>>a;
        for(int j=0;j<a;j++){
            int b,c;cin>>b>>c;
            S[i].push_back(make_pair(b,c));
        }
    }
    dijkstra();
    for(int i=0;i<N;i++){
        cout<<i<<" "<<D[i]<<endl;
    }
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>

using namespace std;
 
vector<int> dijkstra(int s, vector<vector<pair<int, int> > >& G) {
	const int INF = 1e9;
	const int N = G.size();
	vector<int> cost(N, INF);
	priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > pq;
	cost[s] = 0;
	pq.push(make_pair(0, s));
	while (!pq.empty()) {
		pair<int, int> p = pq.top(); pq.pop();
		int now = p.second;
		if (cost[now] < p.first) continue;
		for (auto next : G[now]) {
			int nv = next.first, nw = next.second;
			if (cost[nv] > cost[now] + nw) {
				cost[nv] = cost[now] + nw;
				pq.push(make_pair(cost[nv], nv));
			}
		}
	}
	return cost;
}

int main() {
	int n; cin >> n;
	vector<vector<pair<int, int> > > G(n);
	for (int i = 0; i < n; ++i) {
		int u, k; cin >> u >> k;
		while (k--) {
			int v, c; cin >> v >> c;
			G[u].push_back(make_pair(v, c));
		}
	}
	vector<int> ans(dijkstra(0, G));
	for (int i = 0; i < n; ++i)
		cout << i << " " << ans[i] << endl;

	return 0;
}