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への重み最小の親
	sum     int         // 始点からの距離
	color   color
}

func (p *node) getMinToMst() int {
	if p.parent == nil {
		return math.MaxInt32
	}
	return p.weights[p.parent.num]
}

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, 0, 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].parent = nodes[0]

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

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

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

		// MSTに追加する頂点決定
		minNode.color = mst
		// 自分の親の合計値と合算する
		minNode.sum = minNode.parent.sum + min

		// MSTに属していない頂点それぞれについて,MSTとの最小の重みの距離を加算
		for _, v := range nodes {
			if v.color == mst {
				continue
			}
			w, ok := v.weights[minNode.num]
			if !ok {
				// minNodeと接してない
				continue
			}

			if w < v.getMinToMst() {
				// minNodeへの距離がもっとも重みが少ないので親を変更
				v.parent = minNode
			}
		}
	}

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

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"bits/stdc++.h"
using namespace std;

#define NIL -1
#define MAX (1 << 24)

struct Node {
	int dis = MAX;
	bool flag = false;
	vector<int> d;
	vector<int> id;
};

void dijkstra(vector<Node>& u)
{
	u[0].dis = 0;

	while (1)
	{
		int mini = MAX;
		int n;
		for (int i = 0; i < u.size(); i++)
		{
			if (!u[i].flag && u[i].dis < mini) {
				mini = u[i].dis;
				n = i;
			}
		}

		if (mini == MAX) return;
		u[n].flag = true;

		for (int i = 0; i < u[n].id.size(); i++)
		{
			if (u[u[n].id[i]].flag) continue;
			if ((u[n].dis + u[n].d[i]) < u[u[n].id[i]].dis) {
				u[u[n].id[i]].dis = u[n].dis + u[n].d[i];
			}
		}
	}
}

int main(void)
{
	int i, N, v, k, c, x;
	cin >> N;
	vector<Node> u(N);
	for (i = 0; i < N; i++)
	{
		cin >> v >> k;
		for (int j = 0; j < k; j++)
		{
			cin >> x >> c;
			u[v].id.push_back(x);
			u[v].d.push_back(c);
		}
	}

	
	dijkstra(u);

	for (i = 0; i < N; i++) cout << i << " " << u[i].dis << endl;

	return 0;
}

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

using namespace std;

int main() {

	int INF = 100001;

	int n;
	scanf("%d", &n);

	vector<pair<int, int>> G[n];
	for (int i = 0; i < n; ++i) {
		int from;
		scanf("%d", &from);

		int v;
		scanf("%d", &v);

		for (int j = 0; j < v; ++j) {
			int to;
			int w;
			scanf("%d %d", &to, &w);
			G[from].push_back(make_pair(to, w));
		}
	}

	int C[n];
	for (int i = 0; i < n; ++i)
		C[i] = INF;

	int color[n];
	int WHITE = 0;
	int BLACK = 1;
	for (int i = 0; i < n; ++i)
		color[i] = WHITE;

	priority_queue<pair<int, int>> PQ;
	PQ.push(make_pair(0, 0));
	C[0] = 0;
	while (!PQ.empty()) {
		int u = PQ.top().second;
		PQ.pop();
		color[u] = BLACK;
		for (int i = 0; i < (int) G[u].size(); ++i) {
			auto c = G[u][i];
			if (color[c.first] != BLACK && c.second + C[u] < C[c.first]) {
				C[c.first] = c.second + C[u];
				PQ.push(make_pair(C[c.first] * -1, c.first));
			}
		}
	}

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

	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <stack>
#include <cctype>
#include <cmath>

using namespace std;

/* typedef */

typedef long long ll;

/* constant */

const int INF = 1 << 30;
const int MAX = 100;
const int mod = 1000000007;
const double pi = 3.141592653589;

const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;

/* global variables */
vector< vector<pair<int, int> > > Adj(MAX, vector<pair<int, int> >());
vector<int> color(MAX, WHITE);
vector<int> d(MAX, INF);
vector<int> p(MAX, -1);
int n;

/* function */
void dijkstra();

/* main */
int main() {
    
    cin >> 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;
            Adj[u].push_back(make_pair(v, c));
        }
    }

    dijkstra();

    for (int i = 0; i < n; i++ ) {
        cout << i << ' ' << d[i] << '\n';
    }
   

}

void dijkstra() {

    pair<int, int> p1;
    d[0] = 0;
    p[0] = -1;

    priority_queue<pair<int, int> > PQ;
    PQ.push(make_pair(0, 0));

    while (!PQ.empty()) {

        p1 = PQ.top(); PQ.pop();
        int u = p1.second;
        color[u] = BLACK;

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

        for (auto p2 : Adj[u]) {

            int v = p2.first;
            int cost = p2.second;

            if (color[v] != BLACK) {
                if (d[u] + cost < d[v]) {
                    p[v] = u;
                    d[v] = d[u] + cost;
                    color[v] = GRAY;
                    PQ.push(make_pair(-d[v], v));
                }
            }
        }
    }

}

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

using namespace std;
int d[10002];
struct Edge{
    int from,to,w;
};
const int inf=1<<30;
vector<Edge> E;
vector<int> G[10002];
struct node{
    int to,w;
    friend bool operator < (const node& a, const node& b){
        return a.w>b.w;
    }
};
bool vis[10002];
int V;
void dijkstar(int start=0){
    priority_queue<node> que;
    que.push(node {start,0});
    d[start]=0;
    while(!que.empty()){
        node s=que.top();
        que.pop();
        int nowV=s.to,w=s.w;
        if(vis[nowV]) continue;
        vis[nowV]=true;
        for(int i=0;i<G[nowV].size();i++){
            Edge ee=E[G[nowV][i]];
            if(d[ee.to]>d[nowV]+ee.w){
                d[ee.to]=d[nowV]+ee.w;
                que.push(node {ee.to,d[ee.to]});
            }
        }
    }
}

int main(){
    cin>>V;
    for(int i=0;i<V;i++){
        int id,k;
        cin>>id>>k;
        vis[i]=false;
        d[i]=inf;
        while(k--){
            int out,val;
            cin>>out>>val;
            E.push_back(Edge{id,out,val});
            G[id].push_back(E.size()-1);
        }
    }
    dijkstar();
    for(int i=0;i<V;i++){
        cout<<i<<" "<<d[i]<<endl;
    }
}

C++: #include<iostream>
#include<cstdio>
#include<climits>
#include<cstring>
#include<algorithm>
#define INF 1<<25
using namespace std;
typedef long ull;
 
int main(){
  int n;
  int A[1000][1000];
  ull D[1000][1000];
  scanf("%d",&n);
  int u,k,C,V;
  
  for(int i=0;i<=n;i++){
    for(int j=0;j<=n;j++)D[i][j] = INF;
  }
  
  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;
}