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>
//#include<iostream>
using namespace std;
//type
typedef long long ll;
#define pii pair<int, int>
#define vi vector<int>
//x * y * 1.0 can cause overflow
//constant
#define inf (int)(1e9+7)
#define mod (ll)(1e9+7)
#define eps 1e-10
//omission
#define eb emplace_back
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define all(v) v.begin(), v.end()
#define ios cin.tie(0); ios::sync_with_stdio(false)
#define FIX(a) cout << fixed << setprecision(a)
#define mp make_pair
//manip
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(unique(v.begin(), v.end(), v.end());
#define fill(x, y) memset(x, y, sizeof(x))
#define ceil(a, b) a / b + !!(a % b)
template<class T> T power_mod(T a, T b) {return b ? power(a * a % inf, b / 2) * (b % 2 ? a : 1) % inf : 1;}
template<class T> T power(T a, T b) {return b ? power(a * a, b / 2) * (b % 2 ? a : 1) : 1;}
#define LB(v, x) (int)(lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (int)(upper_bound(v.begin(), v.end(), x) - v.begin())
template<typename T> T gcd(T a, T b) {if (b == 0) return a; return gcd(b, a % b);}
template<typename T> T lcm(T a, T b) {return a / gcd(max(a, b), min(a, b)) * b;} //先に割る!!
#define outa(a, n) rep(i_, n) cout << a[i_] << " "; cout << endl
#define out(a) cout << a << endl
#define outv(v) rep(i, SZ(v)) cout << v[i] << " "; cout << endl
//loop
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep3(i, st, n) for (int i = st; i < n; ++i)
//algorithm
//double pointer, l start, how many adds, can be 0 -> init r = l, sum = 0
//bfs, not x, y, i, j
//not !(i % 2), i % 2 == 0
//minimal required terms
//cast caution
//look constraints always
//ctrl + command + e -> 変数一括変更



int main() {
    
    
   
    int n; cin >> n;
    int table[n]; fill_n(table, n, inf); //0からの距離
    table[0] = 0;
    vector<vector<pii> > edge(n);
    rep(i, n) {
        int u, k; cin >> u >> k;
        rep(j, k) {
            int v, c; cin >> v >> c;
            edge[u].eb(v, c);
        }
        
    }
    
    while (1) {
        int update = 0;
        rep(from, n) {
            rep(j, SZ(edge[from])) {
                int to = edge[from][j].F;
                int cost = edge[from][j].S;
                
                if (table[to] > table[from] + cost) {
                    update = 1;
                    table[to] = table[from] + cost;
                }
            }
        }
        if (update == 0) break;
    }
    
    out(0 << " " << 0);
    rep3(i, 1, n) out(i << " " << table[i]);
        
        
    
    
    
}

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

#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

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

    int n;
    cin >> n;

    vector<vector<pair<int, int>>> g(n);

    rep(i, 0, n) {
        int u, k;
        cin >> u >> k;

        rep(j, 0, k) {
            int v, c;
            cin >> v >> c;
            g[u].push_back(make_pair(v, c));
        }
    }

    vector<bool> seen(n, false);
    vi ds(n, INT_MAX);
    priority_queue<pair<int, int>> pq;

    ds[0] = 0;
    pq.push(make_pair(0, 0));  // (cost, v)

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

        int u = p.second;
        int minv = -p.first;

        if (seen[u]) { continue; }

        seen[u] = true;

        for (auto itr = g[u].begin(); itr != g[u].end(); ++itr) {
            int v = (*itr).first;
            int c = (*itr).second;

            if (!seen[v] && c != INT_MAX && ds[v] > minv + c) {
                ds[v] = minv + c;
                pq.push(make_pair(-ds[v], v));
            }
        }
    }

    rep(i, 0, n) { cout << i << " " << ds[i] << endl; }

    return 0;
}

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

struct edge{int to,cost;};

//pair<int,int> ??????first??????????????¢,second??????????????????

int v;
vector<edge> g[10000];
int d[10000];
const int INF = 10000000;

//s?????????????????????!
void dijkstra(int s){

  priority_queue<pair<int,int>, vector<pair<int,int> >, greater<pair<int,int> > > que;
  fill(d,d+v,INF);
  d[s] = 0;
  que.push(pair<int,int>(0,s));


  while(!que.empty()){
    pair<int,int> p = que.top(); que.pop();
    int k = p.second;
    if(d[k] < p.first) continue;

    for(int i=0; i<g[k].size();i++){
      edge e = g[k][i];
      if(d[e.to] > d[k] + e.cost){
        d[e.to] = d[k] + e.cost;
        que.push(pair<int,int>(d[e.to],e.to));
      }
    }
  }

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

int main(){

    cin >> v;

    int u,k,b,c;

    for(int i=0;i<v;i++){
      cin >> u >> k;
      for(int j=0;j<k;j++){
        cin >> b >> c;
        edge ed;
        ed.to = b;
        ed.cost = c;
        g[i].push_back(ed);
      }
    }

    dijkstra(0);


    return 0;
}

C++: #include<iostream>
using namespace std;
#include<queue>
#include<vector>
#include<string>
#include<string.h>
#include<algorithm>
bool b[2003];

#define REP(i, a) for(int i=0;i<a;i++)
	int N=1000000;
int main()
{
	int min,b,a,k,m[101][101],n ,e,p[101],d[101],u,v; //u ?????????v????????¨
	bool color[101];
	cin>>n;
	REP(i, n) {
		REP(j, n) {
		m[i][j]=N;
		}
	}
	REP(i, n) {
		cin>>u>>k;
		REP(i, k) {
			cin>>a>>b;
			m[u][a]=b;
			if(m[u][a]==-1) m[u][a]=N;
		}
		color[i]=0;
		d[i]=N;
	}
	a=0;
	d[0]=0;
	while(1){
		min=N;
		u=-1;
		REP(i,n){
			if(min>d[i]&&color[i]==0){
				min=d[i];
				u=i;
			}
		}
		if(u==-1) break;
		color[u]=1;
		REP(i,n){
			if(color[i]==0&&m[u][i]!=N){
				if(d[i]>m[u][i]+d[u]){
					d[i]=m[u][i]+d[u];
				}
			}
		}

	}
	min=0;
	REP(i,n){
		cout<<i<<" "<<(d[i] == N ? -1 : d[i])<<endl;
	
	}
	return 0;
}