Go: package main

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

const MAX = 100
const INFTY = math.MaxInt64
const WHITE = 0
const GRAY = 1
const BLACK = 2

var n int
var M [MAX][MAX]int

func dijkstra() {
	var minv int
	var d [MAX]int
	var color [MAX]int

	for i := 0; i < n; i++ {
		d[i] = INFTY
		color[i] = WHITE
	}

	d[0] = 0
	color[0] = GRAY
	for {

		minv = INFTY
		u := -1
		for i := 0; i < n; i++ {
			if minv > d[i] && color[i] != BLACK {
				u = i
				minv = d[i]
			}
		}
		if u == -1 {
			break
		}

		color[u] = BLACK

		for v := 0; v < n; v++ {
			if color[v] != BLACK && M[u][v] != INFTY {
				if d[v] > d[u]+M[u][v] {
					d[v] = d[u] + M[u][v]
					color[v] = GRAY
				}
			}
		}

	}
	for i := 0; i < n; i++ {
		fmt.Printf("%v %v\n", i, d[i])
	}
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ = strconv.Atoi(sc.Text())

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			M[i][j] = INFTY
		}
	}

	for i := 0; i < n; i++ {
		sc.Scan()
		f, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())
		for j := 0; j < k; j++ {
			sc.Scan()
			v, _ := strconv.Atoi(sc.Text())
			sc.Scan()
			c, _ := strconv.Atoi(sc.Text())
			M[f][v] = c
		}
	}
	dijkstra()
}

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

using namespace std;

const int INF = 1 << 30;

struct edge {
	int cost; //重み(距離)
	int to; //行先の頂点
};

void dijkstra(const int n, const vector<vector<edge>> &G, const int stpoint) {

	//優先キューは最短距離と頂点番号のペア、 距離を降順に並べる
	priority_queue<pair<int, int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;

	vector<bool> seen(n,false); //訪問完了でtrue
	vector<int> cost(n,INF); //頂点nまでの距離

	cost[stpoint] = 0;
	pq.push(make_pair(0, 0));

	while (pq.empty() == false) {

		//ターゲット頂点設定（すでに決定したものの中のどれか）
		pair<int, int> target = pq.top();
		int tnum = target.second; //ターゲット頂点番号
		pq.pop();
		
		seen[tnum] = true;

		if (cost[tnum] < target.first) { continue; } //これの意味が分からない保留

		for (unsigned int j = 0; j < G[tnum].size(); j++) { //ターゲットから繋がる先を全部探す

			int v = G[tnum][j].to; //繋がる先の頂点をvにする

			if (seen[v] == true) { continue; } //もう見たとこ（仲間に入ってる）ならスキップ

			if (cost[v] > cost[tnum] + G[tnum][j].cost) {
				cost[v] = cost[tnum] + G[tnum][j].cost;
				pq.push(make_pair(cost[v], v));
			}
		}
	}

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

}

int main() {

	int n;
	cin >> n;

	int stpoint = 0; //この問題では0起点

	vector<vector<edge>> G(n);

	int in1, in2, in3, in4;
	for (int i = 0; i < n; i++) {
		cin >> in1 >> in2;
		for (int j = 0; j < in2; j++) {
			cin >> in3 >> in4;
			G[in1].push_back({ in4, in3 });
		}
	}

	dijkstra(n,G,stpoint);

	return 0;
}

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

using namespace std;

const int maxn=10000;
const int inf=(1<<20);

int n;
vector<pair<int,int> > adj[maxn];

void Dijkstra(){
    priority_queue<pair<int,int> > PQ;
 //   int color[maxn];
    bool vis[maxn];
    int d[maxn];
    for(int i=0;i<n;i++){
        d[i]=inf;
     //   color[i]=white;
        vis[i]=false;
    }

    d[0]=0;
    PQ.push(make_pair(0,0));
 //   color[0]=gray;
  //  vis[0]=1;

    while(!PQ.empty()){
        pair<int,int> f=PQ.top();PQ.pop();
        int u=f.second;

      //  color[u]=black;
        vis[u]=true;

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

        for(int j=0;j<adj[u].size();j++){
            int v=adj[u][j].first;
            if(vis[v]==true) continue;
            if(d[v]>d[u]+adj[u][j].second){
                d[v]=d[u]+adj[u][j].second;
    // priority_queue priority_queue 默认优先较大值， 因此要乘以-1。
                PQ.push(make_pair(d[v]*(-1),v));
              //  vis[v]=true;这句不能加
              //  color[v]=gray;
            }
        }
    }

    for(int i=0;i<n;i++){
        printf("%d %d\n",i,(d[i]==inf?-1:d[i]));
    }
}

int main(){
    int k,u,v,c;

    scanf("%d",&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);
            adj[u].push_back(make_pair(v,c));
        }
    }

    Dijkstra();

    return 0;
}

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

typedef int Weight;
struct Edge {  
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : 
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
const int INF=1e8;

bool shortestPath(const Graph &g,int s,vector<Weight> &dist, vector<int> &prev) {
  int n = g.size();
  dist.assign(n, INF+INF); dist[s] = 0;
  prev.assign(n, -2);
  bool negative_cycle = true;
  for(int k=0;k<n;k++){
    for(int i=0;i<n;i++){
      for(auto e : g[i]){
        if(dist[e.dst] > dist[e.src] + e.weight){
          dist[e.dst] = dist[e.src] + e.weight;
          prev[e.dst] = e.src;
          if(k == n-1){
            dist[e.dst] = -INF;
            negative_cycle = false;
          }
        }
      }
    }
  }
  return negative_cycle;
}

int main(){
	int n; cin >> n;
	Graph g(n);
    int u, k, v, c;
    for(int i=0; i<n; i++){
        cin >> u >> k;
        for(int j=0; j<k; j++){
            cin >> v >> c;
            g[u].push_back({u, v, c});
        }
    }

    vector<Weight> dist;
    vector<int> prev; 
    shortestPath(g, 0, dist, prev);
    
    for(int i=0; i<n; i++){
        cout << i << " " << dist[i] << endl;
    }
}

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

const int INF = LONG_LONG_MAX;
typedef pair<int, int> P;
#define int long long

struct edge {int to, cost;};

/*
[input]
const vector<vector<edge>> &graph : ??\?????°??????
int s : ?§????
int g : ??????
n*/
int dijkstra(const vector<vector<edge>> &graph, int s, int g ) {
  // ????????????????±?????????????????????????
  vector<int> d(graph.size(), INF);
  // ????§?????????????????????????0????????????
  d[s] = 0;
  // ??????????????????now
  set<P> now;
  // ????§?????????????now????????\
  now.insert(P(0, s));
  
  // now????????????????????§
  while(!now.empty()) {
    // ?????¨?????????????????????pos???????´?
    int pos = now.begin()->second;
    // ?????¨??????????????????????????????????±???????????????????????????????
    if (pos == g) {
      for(int i = 0; i <= g; i++) {
        cout << i << " " << d[i] << endl;
      }
      return INF;
    }
    // now????????¢?´¢?????????????¶????
    now.erase(now.begin());
    // ?????¨??????????????¨???????????¢?´¢
    for(auto ed: graph[pos]) {
      // ??\?¶??????????????????????????????????????????¨??????????????§????????????
      // ??¨??\?¶?????????§?????¨????????????????????????????????§???????????°
      if(d[ed.to] > d[pos] + ed.cost) {
        // now????????\?¶?????????????????±????????????????????????????
        now.erase(P(d[ed.to], ed.to));
        d[ed.to] = d[pos] + ed.cost;
        now.insert(P(d[ed.to], ed.to));
      }
    }
  }
  return INF;
}
  
signed main() {
  int num;
  cin >> num;
  vector<vector<edge>> graph(num, vector<edge>());
  int f, n, k, v, c;
  for(int i = 0; i < num; i++) {
    cin >> f >> k;
	if(k == 0) continue;
    for(int j = 0; j < k; j++) {
      cin >> v >> c;
      graph[f].push_back(edge{v, c});
      graph[v].push_back(edge{f, c});
    }
  }
  dijkstra(graph, 0, num - 1);
  return 0;
}