Go: package main

import (
	"fmt"
	"os"
	"bufio"
	"strings"
	"strconv"
)
var MAX = 1000000
type Vertex struct{
	Value int
	Routes map[int]int
	Done bool
}
func NewVertex(value int) *Vertex{
	routes := make(map[int]int)
	// for i, _ := range routes {
	// 	routes[i] = MAX
	// }
	return &Vertex{ value, routes, false }
}

func (v *Vertex) SetRoute(key, weight int) {
	v.Routes[key] = weight
}

type Path struct {
	Key int
	Weight int
}

var count = 0
func ShortestRoutes(list []*Vertex) []int {
	// create result table
	result  := make([]int, len(list))
	// fmt.Println(result)
	for i, _ := range result {
		result[i] = MAX
	}

	queue := make([]Path, 0)
	queue = append(queue, Path{0, 0})
	result[0] = 0

	for len(queue) != 0 {
		count++
		path := queue[0]
		queue = queue[1:]
		for key, weight := range list[path.Key].Routes {
			// fmt.Println(list[path.Key].Routes)
			// set to result
			// fmt.Printf("Path(%d, %d) ? result[%d] => %d, wieght: %d\n", path.Key, path.Weight, key, result[key], weight)
			if path.Weight + weight < result[key] {
				result[key] = path.Weight + weight 
				queue = append(queue, Path{key, result[key]})
			// } else if !list[key].Done {
			// 	queue = append(queue, Path{key, result[key]})
			}
		}
		list[path.Key].Done = true
	}
	return result
}
func main() {
	var n int
	fmt.Scanf("%d", &n)
	list := make([]*Vertex, n)
	scanner := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		scanner.Scan()
		elements := strings.Split(scanner.Text(), " ")
		value, _ := strconv.Atoi(elements[0])
		list[i] = NewVertex(value)
		for j := 2; j < len(elements); j += 2 {
			key, _    := strconv.Atoi(elements[j])
			weight, _ := strconv.Atoi(elements[j + 1])
			list[i].SetRoute(key, weight)
		}
	}

	result := ShortestRoutes(list)
	for i := 0; i < len(result); i++ {
		fmt.Printf("%d %d\n", i, result[i]);
	}
	// fmt.Printf("count: %d\n", count)
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


void Dijkstra(int s, const vector<vector<P>> &g, vector<int> &dis) {
  priority_queue<P, vector<P>, greater<P>> que; // pair = (cost, v);
  dis[s] = 0;
  que.emplace(0,s);
  while(!que.empty()) {
    P p = que.top(); que.pop();
    int now = p.second;
    if(dis[now] < p.first) continue;
    for(P np : g[now]) {
      int next = np.second;
      if(dis[next] > dis[now] + np.first) {
        dis[next] = dis[now] + np.first;
        que.emplace(dis[next], next);
      }
    }
  }
}


int main(){
    
    int n;
    cin >> n;
    V<V<P>> g(n); // pair = (cost, to);
    rep(i,n) {
        int a, k;
        cin >> a >> k;
        rep(j,k) {
            int b, v;
            cin >> b >> v;
            g[a].emplace_back(v,b);
        }
    }

    V<int> d(n, inf);
    Dijkstra(0,g,d);
    rep(i,n) {
        printf("%d %d\n", i, d[i]);
    }
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <climits>
#include <queue>

#define INF INT_MAX

using namespace std;

int main(){
  int n; cin >> n;
  vector<pair<int,int> > G[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(make_pair(v,c));
    }
  }
  //dijkstra from 0
  priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > PQ;
  int visited[n],d[n];
  for(int i=0;i<n;i++){
    visited[i]=0;
    d[i]=INF;
  }
  d[0]=0;
  PQ.push(make_pair(d[0],0));
  while(PQ.empty()==false){
    int u=PQ.top().second;
    int u_first=PQ.top().first;
    PQ.pop();
    //cout << "u:" << u << endl;
    visited[u]=1;
    if(d[u]<u_first) continue;
    for(int i=0;i<G[u].size();i++){
      int v=G[u][i].first;
      //cout << "v:" << v << endl;
      if(visited[v]==0){
        if(d[u]+G[u][i].second<d[v]){
          d[v]=d[u]+G[u][i].second;
          PQ.push(make_pair(d[v],v));
        }
      }
    }
  }
  for(int i=0;i<n;i++) cout << i << " " << d[i] << endl;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define MAX 10000
#define INF (1 << 21)
#define WHITE  1
#define GRAY  2
#define BLACK  3
using namespace std;

int n;
vector<pair<int, int> > adj[MAX];

void dijkstra(){
  priority_queue<pair<int, int> > pq;

  vector<int> color(MAX);
  vector<int> d(MAX);
  
  for(int i = 0; i < n; i++){
    d[i] = INF;
    color[i] = WHITE;
  }

  d[0] = 0;

  pq.push(make_pair(0, 0));

  color[0] = GRAY;

  while(!pq.empty()){
    pair<int, int> f = pq.top();
    pq.pop();

    int u = f.second;

    color[u] = BLACK;

    if(d[u] < f.first * (-1)) continue;

    for(int i = 0; i < adj[u].size(); i++){
      int v = adj[u][i].first;

      if(color[v] == BLACK) continue;
      if(d[v] > d[u] + adj[u][i].second){
	d[v] = d[u] + adj[u][i].second;
	pq.push(make_pair(d[v] * (-1), v));
	color[v] = GRAY;
      }
    }
  }

  for(int i = 0; i < n; i++){
    cout << i << " " << (d[i] == INF ? -1:d[i]) << endl;
  }
}

int main()
{
  int k, u, v, c;

  cin >> n;

  for(int i = 0; i < n; i++){
    cin >> u >> k;

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

  dijkstra();

  return 0;

}