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<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<sstream>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define mod 1000000007
typedef long long ll;
////////////////////////////////////////////////////////////

typedef struct edge_{
	int to,cost;
}edge;

class graph{ 
	typedef long cost_type;
	typedef int edge_type;
	typedef pair<cost_type,edge_type> P; 	//first:最短経路コスト second:頂点番号
	
	
	private:
		vector<vector<edge> > gra; 	//グラフ本体
		priority_queue<P,vector<P>,greater<P> > que; 	//最短経路の値の小さいものから取り出せる
		edge_type V; 	//頂点の個数
	  vector<cost_type> dp; 	//開始地点からの最小コストを格納する配列
	
	public:
		void init(int num){
			V = num;
			dp.assign(V,0x7FFFFFFF);
			gra.assign(V,vector<edge>());
		}


		void setCost(edge_type from , edge_type to , edge_type cost){
			edge e = {to , cost};
			edge e2 = {from , cost};
			gra[from].push_back( e );
			gra[to].push_back(e2);
		}	

		
		void setDirectCost(edge_type from , edge_type to , edge_type cost){
			edge e = {to , cost};
			gra[from].push_back( e );
		}	


		void dijkstra(edge_type s){
			dp[s] = 0;
			que.push(pair<cost_type,edge_type>(0,s)); 

			while(!que.empty()){
				P p = que.top();
				que.pop();
				edge_type v = p.second;
				if( dp[v] > p.first ) continue;
				for(edge_type i = 0 ; i < gra[v].size() ; i++ ){
					edge e = gra[v][i];
					if( dp[e.to] > dp[v] + e.cost ){
						dp[e.to] = dp[v] + e.cost;
						que.push(pair<cost_type,edge_type>(dp[e.to],e.to));
					}
				}
			}
		}

		cost_type getCost(edge_type to){
			return dp[to];
		} 

};

int main(){
	graph g;
	int n;
	cin >> n;
	g.init(n);
	rep(i,0,n){
		int from , k;
		cin >> from >> k;
		rep(i,0,k){
			int to;
			long cost;
			cin >> to >> cost;
			g.setDirectCost(from,to,cost);
		}

	}

	g.dijkstra(0);

	rep(i,0,n)
		cout << i << " " << g.getCost(i) << endl;

	ret 0;
}

C++: #include <cstdio>
#include <unordered_map>
#define N 100
#define INF 0x7FFFFFFF

void solve(std::unordered_map<int, int> a[N], const int n){
    std::unordered_map<int, int> result;
    result.insert(std::make_pair(0, 0));
    while(result.size() != n){
        std::pair<int, int> newV;
        newV.first = INF;
        newV.second = INF;
        for(auto &x: result){
            for(auto &y: a[x.first]){
                int w = y.second + x.second;
                if(result.find(y.first) == result.end() && newV.second > w){
                    newV.first = y.first;
                    newV.second = w;
                }
            }
        }
        result.insert(newV);
    }
    for(int i = 0; i < n; ++i){
        std::printf("%d %d\n", i, result.find(i)->second);
    }
}

int main(){
    int n;
    std::scanf("%d", &n);
    std::unordered_map<int, int> a[N];
    for(int i = 0; i < n; ++i){
        int id;
        std::scanf("%d", &id);
        int num;
        std::scanf("%d", &num);
        for(int j = 0; j < num; ++j){
            std::pair<int, int> v;
            std::scanf("%d", &v.first);
            std::scanf("%d", &v.second);
            a[i].insert(v);
        }
    }
    solve(a, n);
    return 0;
}

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

typedef pair<int, int> P;
const int N = 2e5;
const int INF = 1e9;

struct edge{ int to,cost; };
vector< edge > G[N];
int n;

void dikstra(int s){
  priority_queue<P,vector<P>,greater<P>> que;
  int d[N]; //sからの最短距離
  fill(d,d+N,INF);
  d[s] = 0;
  que.push({0,s}); //{頂点,最短距離}

  while( !que.empty() ){
    P p = que.top(); que.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;
        que.push( {d[e.to],e.to} );
      }
    }
  }

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

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

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

  return 0;
}

C++: #include <iostream>
#include <ios>
#include <vector>
#include <queue>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;

constexpr int INF = 1 << 30;

void read_graph(int n, vector<vector<pair<int, int>>> & Es){
    int u, k, v, c;
    while (n--){
        cin >> u >> k;
        while(k--){
            cin >> v >> c;
            Es[u].push_back(pair<int, int>(v, c));
        }
    }
}

void dijkstra(int start, const vector<vector<pair<int, int>>> & Es, vector<int> & dist){
    priority_queue<pair<int, int>, vector< pair<int, int> >, greater<pair<int, int> > > pq;
    pq.emplace(0, start);
    int d, u, v, c;
    while(!pq.empty()){
        tie(d, u) = pq.top();
        pq.pop();
        if (dist[u] < d) continue;
        dist[u] = d;
        for (auto p : Es[u]){
            tie(v, c) = p;
            if (d + c < dist[v]){
                dist[v] = d + c;
                pq.emplace(d + c, v);
            }
        }
    }
}

int main()
{
    ios::sync_with_stdio(false);
    int n = 0;
    cin >> n;
    vector< vector< pair<int, int> > > Es(n);
    vector<int> dist(n, INF);
    
    read_graph(n, Es);
    dijkstra(0, Es, dist);
    
    for (int i = 0; i != n; ++i){
        cout << i << ' ' << dist[i] << endl;
    }
    return 0;
}