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 <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef pair<ll, ll> P;

ll squareDis(P x, P y){
    return (x.fs - y.fs) * (x.fs - y.fs) + (x.sc - y.sc) * (x.sc - y.sc);
}

bool judgeAcute(P x, P y, P z){
    ll dis1 = squareDis(x, y);
    ll dis2 = squareDis(x, z);
    ll dis3 = squareDis(y, z);

    return dis1 + dis2 > dis3;

}

class Graph{
    struct edge{
        int vertice;
        ll weight;
    };

    vector<vector<edge>> g;
    unsigned int n;

public:
    Graph(unsigned int n): n{n}{
        g.resize(n);
    }

    void add_edge(int u, int v){
        g[u].emplace_back(edge{v, 1});
    };

    void add_edge(int u, int v, ll w){
        g[u].emplace_back(edge{v, w});
    }

    vector<edge>& get_edge(int v){
        return g[v];
    }

    unsigned int get_num_vertices(){
        return n;
    }

    vector<edge>& operator[](int v){
        return get_edge(v);
    }
};


/**
 *
 * @param s 始点
 * @param g グラフ
 * @return sから各頂点への距離
 */
vector<ll> dijkstra1(int s, Graph g, ll INF=LONG_LONG_MAX / 3){
    unsigned int n = g.get_num_vertices();
    vector<bool> used(n, false);
    vector<ll> d(n, INF);

    d[s] = 0;
    while(true){
        int v = -1;
        for(int u = 0; u < n; u++) {
            if (!used[u] && (v == -1 || d[u] < d[v])) {
                v = u;
            }
        }

        if(v == -1) break;

        used[v] = true;
        for(auto e: g[v]){
            d[e.vertice] = min(d[e.vertice], d[v] + e.weight);
        }
    }

    return d;
}


vector<ll> dijkstra2(int s, Graph g, ll INF=LONG_LONG_MAX / 3){
    typedef pair<ll, int> Ptmp;  // firstは最短距離、secondは頂点の番号

    unsigned int n = g.get_num_vertices();
    priority_queue<Ptmp, vector<Ptmp>, greater<Ptmp>> que;
    vector<ll> d(n, INF);

    d[s] = 0;
    que.push(Ptmp(d[s], s));

    while(!que.empty()){
        Ptmp p = que.top();   que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        for(auto e: g[v]){
            if(d[e.vertice] > d[v] + e.weight){
                d[e.vertice] = d[v] + e.weight;
                que.push(Ptmp(d[e.vertice], e.vertice));
            }
        }
    }

    return d;
}



int main(){
    uint n;  cin >> n;
    Graph 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.add_edge(u, v, c);
        }
    }

    vector<ll> res = dijkstra2(0, g);
    for(int i = 0; i < n; i++){
        cout << i << " " << res[i] << endl;
    }
}


//int main(){
//    int n, m;   cin >> n >> m;
//
//    vector<vector<edge>> g(100);
//    vector<P> cor(n);
//
//    for(int i = 0; i < n; i++){
//        int x, y;   cin >> x >> y;
//        cor[i] = P(x, y);
//    }
//    for(int i = 0; i < m; i++){
//        int a, b, c;    cin >> a >> b >> c;
//        a--; b--;
//        g[a].emplace_back(edge{c, b});
//        g[b].emplace_back(edge{c, a});
//    }
//
//    vector<vector<edge>> g2;
//    map<P, int> mp;
//    g2.emplace_back(vector<edge>(0));
//    int n2 = 0;
//    mp[P(0, 0)] = n2++;
//
//    for(int i = 0; i < n; i++){
//        for(auto v: g[i]){
//            g2.emplace_back(vector<edge>(0));
//            mp[P(i, v.v)] = n2++;
//        }
//    }
//
//    for(int i = 0; i < n; i++){
//        for(auto v: g[i]){
//            for(auto u: g[i]){
//                if(!judgeAcute(cor[i], cor[u.v], cor[v.v])){
//                    g2[mp[P(i, v.v)]].emplace_back(edge{u.w, mp[P(u.v, i)]});
//                }
//            }
//        }
//    }
//
//
//
//    return 0;
//}