Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

const T = 10000000

var n int
var A [101][101]int

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func Shortestsearch() {
	var Minimum int
	var d, color [100]int
	var u int

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

	d[0] = 0
	color[0] = 1

	for {
		Minimum = T
		u = -1
		for i := 0; i < n; i++ {
			if Minimum > d[i] && color[i] != 2 {
				u = i
				Minimum = d[i]
			}
		}
		if u == -1 {
			break
		}
		color[u] = 2
		for j := 0; j < n; j++ {
			if color[j] != 2 && A[u][j] != T {
				if d[j] > d[u]+A[u][j] {
					d[j] = d[u] + A[u][j]
					color[j] = 1
				}
			}
		}
	}
	for i := 0; i < n; i++ {
		fmt.Printf("%d %d\n", i, d[i])
	}
}
func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			A[i][j] = T
		}
	}
	for i := 0; i < n; i++ {
		u := nextInt()
		k := nextInt()
		for j := 0; j < k; j++ {
			v := nextInt()
			c := nextInt()
			A[u][v] = c
		}
	}
	Shortestsearch()
}

C++: #include<bits/stdc++.h>
#include<limits.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)

#define MAX 101
#define INF INT_MAX

vector<vector<int>> adj_mat(MAX, vector<int>(MAX, INT_MAX));

void dijkstra(int start_node, int node_size){
    vector<int> visited(node_size, 0);
    vector<int> cost_table(node_size, INF);

    int node = start_node;
    cost_table.at(node) = 0;

    while(true){
        // cout << "looking node : " << node << ",  cost : ";
        // rep(i, node_size){
        //     cout << cost_table.at(i) << " "; 
        // }
        // cout << endl;

        visited.at(node) = 1;

        rep(i, node_size){
            if(visited.at(i) == 0 && adj_mat.at(node).at(i) != INF){
                int new_cost = adj_mat.at(node).at(i) + cost_table.at(node);
                if(new_cost < cost_table.at(i)){
                    cost_table.at(i) = new_cost;
                }
            }
        }

        int m = INF;
        rep(i, node_size){
            if(visited.at(i) == 0 && (cost_table.at(i) < m)){
                m = cost_table.at(i);
                node = i;
            }
        }
        if(m == INF){
            break;
        }
    }

    rep(i, node_size){
        cout << i << " " << cost_table.at(i) << endl;
    }

}

int main(){
    int n; cin >> n;
    rep(i, n){
        int u, k; cin >> u >> k;
        rep(j, k){
            int v, c; cin >> v >> c;
            adj_mat.at(u).at(v) = c;
        }
    }

    // rep(i, n){
    //     rep(j, n){
    //         if(adj_mat.at(i).at(j) == INT_MAX) cout << "∞ ";
    //         else cout << adj_mat.at(i).at(j) << " ";
    //     }
    //     cout << endl;
    // }

    dijkstra(0, n);

}

C++: // -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_12_B: Single Source Shortest Path I

#include <algorithm>
#include <cstdio>

using uint = unsigned int;

class Graph {
  const uint n_;
  uint* const g_;
  
public:
  const static uint INFINIT = 100000+1;

  Graph(uint n) : n_(n), g_(new uint[(n_*n_)]) { std::fill_n(g_, (n_*n_), INFINIT); }

  ~Graph() { delete[] g_; }
  
  uint* operator [](uint i) const { return g_+(n_*i); }

  void dijkstra(uint* dist)
  {
    std::fill_n(dist, n_, INFINIT);
    bool visited[n_];
    std::fill_n(visited, n_, false);
    auto i = 0u; // 0-start
    visited[i] = true;
    dist[i] = 0u;
    for (auto n = 0u; n < n_-1; ++n) {
      auto cur_min_dist = INFINIT;
      auto es = (*this)[i];
      auto base_dist = dist[i];
      for (auto j = 0u; j < n_; ++j) {
        if (visited[j]) continue;
        dist[j] = std::min(dist[j], base_dist+es[j]);
        if (cur_min_dist > dist[j]) {
          cur_min_dist = dist[j];
          i = j;
        }
      }
      visited[i] = true;
      dist[i] = cur_min_dist;
    }
  }
};

const uint Graph::INFINIT;

int main()
{
  uint n;
  std::scanf("%u", &n);

  Graph g(n);

  uint u, k, c, v;
  for (auto i = 0u; i < n; ++i) {
    std::scanf("%u %u", &u, &k);
    for (auto j = 0u; j < k; ++j) {
      std::scanf("%u %u", &c, &v);
      g[u][c] = v;
    }
  }

  uint dist[n];
  g.dijkstra(dist);
  for (auto i = 0u; i < n; ++i) {
    std::printf("%u %u\n", i, dist[i]);
  }
}

// eof

C++: import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    int[] distTo = null;
    int[] parentOf = null;

    public Main(ArrayList<ArrayList<Edge>> G){
        distTo = new int[G.size()];
        Arrays.fill(distTo, Integer.MAX_VALUE);
        parentOf = new int[G.size()];

        PriorityQueue<SDto> pq = new PriorityQueue<>();

        pq.add(new SDto(0, 0, -1));
        while (!pq.isEmpty()) {

            SDto optim = pq.poll();

            if (optim.d < distTo[optim.v]) {
                distTo[optim.v] = optim.d;
                parentOf[optim.v] = optim.from;
                for (Edge e : G.get(optim.v)) {
                    if (optim.from != e.v) { // prevent go back
                        pq.add(new SDto(e.v, distTo[optim.v] + e.c, optim.v));
                    }
                }

            }
        }

    }

    private static class SDto implements Comparable<SDto> { // Shortest distance to vertex
        int v, d, from;

        SDto(int v, int d, int from) {
            this.v = v;
            this.d = d;
            this.from = from;
        }

        @Override
        public int compareTo(SDto that) {
            if(this.d > that.d) return 1;
            else if(this.d < that.d) return -1;
            return 0;
        }


    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();

        ArrayList<ArrayList<Edge>> G = new ArrayList<>(n);
        for (int i = 0; i < n; i++) {
            G.add(new ArrayList<>());
        }

        for (int i = 0; i < n; i++) {
            int u = in.nextInt();
            int k = in.nextInt();
            for (int j = 0; j < k; j++) {
                int v = in.nextInt(), c = in.nextInt();
                G.get(i).add(new Edge(v, c));
                G.get(v).add(new Edge(i, c));
            }
        }

        Main dijkstra = new Main(G);

        for (int i = 0; i < G.size(); i++) {
            System.out.printf("%d %d\n", i, dijkstra.distTo[i]);
        }
    }
}

class Edge {
    int v, c;

    Edge(int v, int c) {
        this.v = v;
        this.c = c;
    }

    @Override
    public String toString() {
        return String.format("(v=%d, c=%d)", v, c);
    }
}

C++: #include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n + 1); ++i)
using namespace std;
using ll = long long;
const int INF = +100100100;
// typedef pair<int,int> P;
const int  WHITE = 0;
const int GRAY =1;
const int BLACK =2;
const int NIL = -1;
const int MAX = 100;

// 配列のサイズを大きく取りすぎるとエラーが出ないが、実行できなくなる.
vector<vector<int>> M(MAX,vector<int>(MAX,INF));
vector<int> color(MAX,WHITE), P(MAX,NIL),D(MAX,INF);
int n;

void dijkstra(){
    int u = 0;
    D[u] = 0;
    while(1){
        int mini =INF;
        rep(i,n){
            if(mini>D[i] && color[i]!=BLACK){
                u = i;
                mini = D[i];
            }
        }
        if(mini==INF)break;
        color[u]=BLACK;
        rep(i,n){
            if(color[i]==BLACK)continue;
            if(D[u]+M[u][i]<D[i]){
                D[i] = D[u]+M[u][i];
            }
            color[i]=GRAY;
        }

    }
}

int main(){
    cin >> n;
    rep(i,n){
        int id, m;
        cin >> id>>m;
        rep(j,m){
            int opp;cin>>opp;
            int cost; cin >> cost;
            M[i][opp]=cost;
        }
    }
    dijkstra();
    rep(i,n){
        cout<<i << " " << D[i]<<endl;
    }
    return 0;
}