Go: package main

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

const BIG_COST = 200000

const (
	ST_NOT_YET = iota
	ST_JOINED
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	nNodes := scanInt(sc)

	costs := make([][]int, nNodes)
	graph := make([][]int, nNodes)

	states := make([]int, nNodes)
	costSums := make([]int, nNodes)

	for i := 0; i < nNodes; i++ {
		costs[i] = make([]int, nNodes)
		costSums[i] = BIG_COST
	}

	for i := 0; i < nNodes; i++ {
		u := scanInt(sc)
		k := scanInt(sc)
		graph[u] = make([]int, k)
		for d := 0; d < k; d++ {
			v := scanInt(sc)
			graph[u][d] = v
			costs[u][v] = scanInt(sc)
		}
	}

	costSums[0] = 0
	for {
		minCost := BIG_COST
		var u int

		for i, cost := range costSums {
			if states[i] != ST_JOINED && cost < minCost {
				minCost = cost
				u = i
			}
		}

		if minCost == BIG_COST {
			break
		}

		states[u] = ST_JOINED

		for _, v := range graph[u] {
			cost := minCost + costs[u][v]
			if cost < costSums[v] {
				costSums[v] = cost
			}
		}
	}

	w := bufio.NewWriter(os.Stdout)
	for i, cost := range costSums {
		fmt.Fprintf(w, "%d %d\n", i, cost)
	}
	w.Flush()
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

C++: //ALDS1_12_cにて、AC
#include<bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
int main(){
  int n;
  cin>>n;
  vector<pair<int,int> > adj[10005]; //重み付き有向グラフの隣接リスト表現
  //隣接リストの作成
  int u,k;
  for(int i=0;i<n;i++){
    cin>>u>>k;
    for(int j=0;j<k;j++){
      int v,c;
      cin>>v>>c;
      adj[u].emplace_back(v,c);
    }
  }

  //ここからダイクストラ
  priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > pq;
  vector<bool> fg(n+1000);
  vector<int> cost(n+1000);
  //初期化
  for(int i=0;i<n;i++){
    cost[i]=INF;
    fg[i]=false;
  }
  //出発地点はコスト0
  cost[0]=0;
  pq.emplace(0,0);
 
  //最短経路を検出
  while(!pq.empty()){
    auto now=pq.top(); pq.pop();
    int u=now.second;
    fg[u]=true;

    //最小値を取り出し、それが最短でなければ無視
    if(cost[u]<now.first) continue;
    
    //次の辺へ移動
    for(int j=0;j<adj[u].size();j++){
      int v=adj[u][j].first;
      if(fg[v]) continue;
      if(cost[v]>cost[u]+adj[u][j].second){
        cost[v]=cost[u]+adj[u][j].second;
        //priority_queueはデフォルトで大き値を優先するため、-1をかける。
        pq.emplace(cost[v],v);
      }
    }
  }

  for(int i=0;i<n;i++){
    cout<<i<<" "<<(cost[i]==INFINITY ? -1 : cost[i])<<'\n';
  }
  return(0);
}

C++: #include<cstdio>
#include<stdlib.h>
#include<iostream>

using namespace std;

const int maxn = 105;
int M[maxn][maxn];
int d[maxn];
int p[maxn];
bool visit[maxn];

int main(){
	int n;
	int u,k,v,c;
	cin >> n;
	for(int i = 0;i < n;i++){
		visit[i] = false;
		d[i] = 0x3f3f3f;
		for(int j = 0;j < n;j++){
			M[i][j] = -1;
		}
	}
	
	for(int i = 0;i < n;i++){
		cin >> u >> k;
		for(int j = 0;j < k;j++){
			cin >> v >> c;
			M[u][v] = c;
		}
	}
	
	d[0] = 0;
	int result = 0;
	while(true){
		int u;
		int min_distance = 0x3f3f3f;
		for(int i = 0;i < n;i++){
			if(visit[i])continue;
			if(d[i] < min_distance){
				min_distance = d[i];
				u = i;
			}
		}
		if(min_distance == 0x3f3f3f)break;
		visit[u] = true;
		result += min_distance;
		for(int i = 0;i < n;i++){
			if(visit[i])continue;
			if(M[u][i] == -1)continue;
			if(d[u] + M[u][i] < d[i]){
				d[i] = d[u] + M[u][i];
				p[i] = u;
			}
		}
	}
	for(int i = 0;i < n;i++)cout << i << " " << d[i] << endl;
//	cout << result << endl;
	
}

C++: #include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;


ll M[110][110]; //edge weight
ll color[110];
ll white = 0, gray = 1, black = 2;
ll n; 

void dijkstra(){
  ll d[110];//d[v] vまでの最短経路
  ll minv;
  rep(i, 0, n){
    color[i] = white;
    d[i] = INF;
  }
  d[0] = 0;
  color[0] = gray;
  while(1){
    minv = INF;
    ll u = -1;
    rep(i, 0, n){
      if(minv > d[i] && color[i] != black){// はじめd[i]=0, u = 0, minv = 0
        u = i;
        minv = d[i];
      }
    }
    if(u == -1) break;
    color[u] = black;// 最も重さが小さいほうへすすむ
    rep(v, 0, n){
      if(color[v] != black && M[u][v] != INF){
        if(d[v] > d[u] + M[u][v]){
          d[v] = d[u] + M[u][v]; //d[v]を更新
          color[v] = gray;
        }
      }
    }
  }
  rep(i, 0, n){
    cout << i << " " << d[i] << endl;
  }
}

int main() {
  cin >> n;
  rep(i, 0, n){//始めに辺の重さをマックスに初期化
    rep(j, 0, n) M[i][j] = INF;
  }

  rep(i, 0, n){
    ll u; cin >> u;
    ll k; cin >> k;
    rep(j, 0, k){
      ll v, c; cin >> v >> c;
      M[u][v] = c;//辺の重さを入力
    }
  }

  dijkstra();

  return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;

#define MAX_VERTEX 100
#define INF 1000000

int vertex_num;   // ???????????°

int cost[MAX_VERTEX][MAX_VERTEX]; // ????????????cost[?§????][??????]??§?§?????????????????????????????????¨???
int d[MAX_VERTEX];                // ????????????d[u]??§?§??????¨u??????????????¢?????¨??????
bool used[MAX_VERTEX];            // ????????????????????£????????¢????±???????????????????

void Input() {
	cin >> vertex_num;

	// (a1) ??\???????????¶??§?????????
	// d??¨cost?????¨???INF
	// used????????????false
	for (int i = 0; i < vertex_num; i++){
		d[i] = INF;
		used[i] = false;
		for (int j = 0; j < vertex_num; j++){
			cost[i][j] = INF;
		}
	}



	for (int i = 0; i < vertex_num; i++) {
		int from, out_num;
		cin >> from >> out_num;
		for (int j = 0; j < out_num; j++) {
			int to, c;
			cin >> to >> c;
			cost[from][to] = c;
		}
	}
}

void Dijkstra() {
	// (b1) ?§????????????????
	d[0] = 0;
	while (true) {
		// ????????????????????¨???
		int vertex = -1;

		// (b2) ????????????????????£????????¢????±??????????????????????
		// ?????????????????????????????????????????§????????¢???????°???????????????¢???
		for (int u = 0; u < vertex_num; u++){
			if (!used[u] && (vertex == -1 || d[u] < d[vertex])){
				vertex = u;
			}
		}


		// ??¨????????????????????????????¨?????????????????????´????????????????????????
		if (vertex == -1) break;

		used[vertex] = true;

		// ???????????¢????¨????????????????
		for (int u = 0; u < vertex_num; u++) {
			d[u] = min(d[u], d[vertex] + cost[vertex][u]);
		}

	}

}

void Output() {
	for (int i = 0; i < vertex_num; i++) {
		cout << i << " " << d[i] << endl;
	}
}

int main() {

	Input();
	Dijkstra();
	Output();

	return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
ll dis[105][105],vis[105] = {1,0},sum[105] = {0};
const ll INF = 0x3f3f3f3f;
int main()
{
    int n,i,m,j,a,b,k,mmin,ans = 0;
    cin >> n;
    for(i = 0;i < n;i++)
        for(j = 0;j < n;j++)
            dis[i][j] = INF;
    dis[0][0] = 0;
    for(j = 0;j < n;j++)
    {
        cin >> i >> m;
        while(m--)
        {
            cin >> a ;
            cin >> dis[i][a];
        }
    }
    for(k = 0;k < n;k++)
        for(i = 0;i < n;i++)
            for(j = 0;j < n;j++)
                dis[i][j] = min(dis[i][j],dis[i][k]+dis[k][j]);
    for(i = 0;i < n;i++)
        cout << i << ' ' << dis[0][j] << endl;
    return 0;
}