Go: // ダイクストラのアルゴリズム
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
	"strings"
)

type color int

const (
	white color = iota // 未訪問
	mst                // MSTとして確定
)

// 頂点
type node struct {
	num       int         // 頂点の番号
	weights   map[int]int // 重みMAP
	parent    *node       // MSTへの重み最小の親
	distFromS int         // 始点からの距離
	color     color
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	n := eGetInt(scanner)

	nodes := make([]*node, n)
	for i := 0; i < n; i++ {
		weights := eAtoi((strings.Fields(eGetline(scanner))))
		v := &node{weights[0], make(map[int]int, weights[1]), nil, math.MaxInt32, white}
		for j := 0; j < weights[1]; j++ {
			k := weights[j*2+2] // 相手の頂点名
			w := weights[j*2+3] // 重み
			v.weights[k] = w
		}
		nodes[i] = v
	}

	// 初回はnode[0]がMSTに入るように
	nodes[0].distFromS = 0

	for { // 全部チェックするまで

		// どの頂点を新たにMSTに取り込むか

		var minNode *node
		min := math.MaxInt32
		for _, v := range nodes {
			if v.color == mst {
				continue
			}
			if v.distFromS < min {
				min = v.distFromS
				minNode = v
			}
		}
		if minNode == nil {
			// すべて完了している.
			break
		}

		// MSTに追加する頂点決定
		minNode.color = mst

		// fmt.Printf(">[%v]\n", minNode)
		// MSTに属していない頂点それぞれについて,Startからの最小の重みの距離を更新
		for i, v := range nodes {
			if v.color == mst {
				continue
			}
			w, ok := minNode.weights[i]
			if !ok {
				// minNodeと接してない
				continue
			}

			if minNode.distFromS+w < v.distFromS {
				// minNode経由の距離がもっとも重みが少ないので親を変更
				v.distFromS = minNode.distFromS + w
				v.parent = minNode
				// fmt.Printf("[%v %v]\n", v, minNode)
			}
		}
		// fmt.Printf("<\n")
	}

	for i, v := range nodes {
		fmt.Printf("%d %d\n", i, v.distFromS)
	}
}

func eGetInt(scanner *bufio.Scanner) int {
	t := eAtoi(strings.Fields(eGetline(scanner)))
	return t[0]
}

func eGetline(p *bufio.Scanner) string {
	if !p.Scan() {
		if err := p.Err(); err != nil {
			log.Fatal(err.Error())
		}
		return ""
	}
	return p.Text()
}

func eAtoi(s []string) []int {
	ints := make([]int, len(s))
	var err error
	for i, e := range s {
		ints[i], err = strconv.Atoi(e)
		if err != nil {
			log.Fatal(err.Error())
		}
	}
	return ints
}

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

using namespace std;

struct Node {
    int cost = INT_MAX;
    int color = 0;
    vector<int> next_node;
    vector<int> len_cost;
} node[100];

int main() {
    int n, id, k;

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> id >> k;
        node[id].next_node.resize(k);
        node[id].len_cost.resize(k);
        for (int j = 0; j < k; j++) {
            cin >> node[id].next_node[j] >> node[id].len_cost[j];
        }
    }

    int size1, size2;
    vector<int> vec;
    node[0].cost = 0;
    node[0].color = 1;
    vec.push_back(0);
    while (1) {
        size1 = vec.size();
        if (size1 == n) {
            break;
        }
        for (int i = 0; i < size1; i++) {
            size2 = node[vec[i]].next_node.size();
            for (int j = 0; j < size2; j++) {
                if (node[node[vec[i]].next_node[j]].cost > node[vec[i]].cost + node[vec[i]].len_cost[j]) {
                    node[node[vec[i]].next_node[j]].cost = node[vec[i]].cost + node[vec[i]].len_cost[j];
                }
            }
        }
        int min = INT_MAX, mini;
        for (int i = 0; i < size1; i++) {
            size2 = node[vec[i]].next_node.size();
            for (int j = 0; j < size2; j++) {
                if (min > node[node[vec[i]].next_node[j]].cost && node[node[vec[i]].next_node[j]].color == 0) {
                    min = node[node[vec[i]].next_node[j]].cost;
                    mini = node[vec[i]].next_node[j];
                }
            }
        }
        vec.push_back(mini);
        node[mini].color = 1;
    }

    for (int i = 0; i < n; i++) {
        cout << i << " " << node[i].cost << endl;
    }
    
    return 0;
}

C++: #include <iostream>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <cstring>
#include <cmath>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)

#define debug(x) cerr<<#x<<": "<<x<<'\n'

#define fi first
#define se second

#define vi vector<int>
#define pb push_back
#define mp make_pair

#define pcnt __builtin_popcount

typedef long long ll;

const int inf = 100100100;
const int MOD = 998244353;
const double EPS = 1e-9;

vector<vector<pair<int,int> > > G(110);

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    rep(i,n){
      int u,k;
      cin >> u >> k;
      rep(j,k){
        int v,c;
        cin >> v >> c;
        G[u].push_back(mp(v,c));
        G[v].push_back(mp(u,c));
      }
    }
    int d[110] = {};
    rep(i,110) d[i] = inf;
    d[0] = 0;
    while(true){
        bool update = false;
        rep(i,n){
          for(auto o : G[i]){
            if(d[o.fi] > d[i]+o.se){
                d[o.fi] = d[i]+o.se;
                update = true;
            }
          }
        }
        if(!update) break;
    }
    rep(i,n) cout << i << " " << d[i] << endl;
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#define INF 1<<30
using namespace std;
typedef unsigned long long ull;
int n;
int A[1000][1000];
bool used[1000];
ull D[1000][1000];
 
void Init(int f){
  for(int i=0;i<f;i++){
    for(int j=0;j<f;j++)D[i][j] = INF;
  }
 
}
 
int main(){
  scanf("%d",&n);
  int u,k,C,V;
  Init(n);
  
  for(int i=0;i<n;i++){
      scanf("%d %d",&u,&k);    
      for(int j=0;j<k;j++){
    scanf("%d %d",&V,&C);
    D[u][V] = C;
    D[V][u] = C;
      }    
  }
   
  for(int i=0;i<n;i++)D[i][i] = 0;
  for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++)D[i][j] = min(D[i][j],D[i][k] + D[k][j]);
  for(int i=0;i<n;i++){
    cout << i << " " << D[0][i] << endl;
  }
 
  return 0;
}

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

using namespace std;

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

typedef long long ll;
typedef long double ld;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

const int N = 10001;

using P = pair<int, int>;

int n;

struct edge {
    int to;
    int cost;
};

vector<int> dist(N, Inf);
vector<edge> g[N];

void dijkstra(int s) {
    dist[s] = 0;
    priority_queue<P, vector<P>, greater<P> > pq;
    pq.push(P(0, s));

    while (!pq.empty()) {
        P p = pq.top();
        pq.pop();
        int v = p.second;
        if (dist[v] < p.first) continue;

        rep (i, g[v].size()) {
            edge e = g[v][i];
            if (dist[e.to] > dist[v] + e.cost) {
                dist[e.to] = dist[v] + e.cost;
                pq.push(P(dist[e.to], e.to));
            }
        }
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    cin >> n;
    rep (i, n) {
        int u, k;
        cin >> u >> k;
        rep (j, k) {
            int v, c;
            cin >> v >> c;
            edge e = {v, c};
            g[u].push_back(e);
        }
    }
    dijkstra(0);
    rep (i, n) {
        cout << i << " " << dist[i] << endl;
    }
    
    return 0;
}