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++: /*
 * Input
 * An edge-weighted graph G (V, E) and the source r.
 *
 * |V| |E| r
 * s0 t0 d0
 * s1 t1 d1
 * :
 * s|E|−1 t|E|−1 d|E|−1
 * |V| is the number of vertices and |E| is the number of edges in G. The graph
 * vertices are named with the numbers 0, 1,..., |V|−1 respectively. r is the
 * source of the graph.
 *
 * si and ti represent source and target vertices of i-th edge (directed) and di
 * represents the cost of the i-th edge.
 *
 * Output
 * c0
 * c1
 * :
 * c|V|−1
 * The output consists of |V| lines. Print the cost of the shortest path from
 * the source r to each vertex 0, 1, ... |V|−1 in order. If there is no path
 * from the source to a vertex, print INF.
 *
 * Constraints
 * 1 ≤ |V| ≤ 100000
 * 0 ≤ di ≤ 10000
 * 0 ≤ |E| ≤ 500000
 * There are no parallel edges
 * There are no self-loops
 */

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;

int main() {
  int n, m, source = 0;
  cin >> n; // >> m >> source;
  vector<map<int, int>> adj(100000);

  vector<int> d(100000, 1000000001);
  bool visited[100000];
  int n_visited = 0;

  for (int u, k; cin >> u >> k;) {
    for (int i = 0, v, len; i < k; ++i) {
      cin >> v >> len;
      adj[u][v] = len;
    }
  }

  auto cmp = [&](int s, int t) { return d[s] > d[t]; };
  priority_queue<int, vector<int>, decltype(cmp)> q(cmp);

  d[source] = 0;
  q.push(source);
  while (!q.empty() and n_visited < n) {
    auto u = q.top();
    q.pop();
    if (visited[u])
      continue;
    ++n_visited;
    visited[u] = true;
    for (auto &kv : adj[u]) {
      d[kv.first] = min(d[kv.first], d[u] + kv.second);
      q.push(kv.first);
    }
  }

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

C++: #include<stdio.h>
#include<string.h>
long long arr[205][205];
long long min(long long a,long long b){
	return a>b?b:a;
}
int main() {
    int n,m;
    while(scanf("%d",&n)!=EOF){
    	long long x,y,c,d;
    	for(int i=0;i<205;i++){
    		for(int j=0;j<205;j++){
    		 arr[i][j]=10000000;	
			}
		}
    	for(int j=0;j<n;j++){
    	scanf("%lld %lld",&x,&y);
    	for(int h=0;h<y;h++){
    		scanf("%lld %lld",&c,&d);
    		arr[x][c]=min(arr[x][c],d);
		}
		}
	for(int k=0;k<n;k++){
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				arr[i][j]=min(arr[i][j],arr[i][k]+arr[k][j]);
			}
		}
	}
	printf("0 0\n");
	for(int i=1;i<n;i++){
    printf("%d %lld\n",i,arr[0][i]);
   }
    }
	return 0;
}

C++: #include <iostream>
#include <queue>
#include <vector>
#include <utility>
using namespace std;
typedef pair<int, int> P;
struct edge {int to, cost;};
const int INF = (1 << 28);
int n;
vector<edge> G[110];


vector<int> dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P>> que;
    que.push(P(0, s));
    vector<int> d(n, INF);
    d[s] = 0;
    while (!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        for (auto e: G[v]) {
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
    return d;
}

int main(void) {
    cin >> n;
    for (int i = 0; i < n; i++) {
        int u, k, v, c;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            cin >> v >> c;
            G[u].push_back(edge {v, c});
        }
    }
    vector<int> d = dijkstra(0);
    for (int i = 0; i < n; i++) {
        cout << i << " " << d[i] << endl;
    }

    return 0;
}