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<iostream>
#include<vector>
#include<queue>
#include<tuple>
#include<climits>
using namespace std;

int main(){
  priority_queue <tuple<int,int>,vector<tuple<int,int> >,greater<tuple<int,int> > > checkpoint;
  vector<vector<int> > path;
  vector<int> min_distance;
  int n;

  cin >> n;
  path.resize(n);
  for(int i=0;i<n;i++){
    path[i].resize(n);
    for(int j=0;j<n;j++){
      path[i][j]=INT_MAX;
    }
  }
  min_distance.resize(n);
  for(int i=0;i<n;i++){
    min_distance[i]=INT_MAX;
  }

  for(int i=0,from,to,cost,m;i<n;i++){
    cin >> from >> m;
    for(int j=0;j<m;j++){
      cin >> to >> cost;
      path[i][to]=cost;
    }
  }

  checkpoint.push(make_tuple(0,0));
  while(!checkpoint.empty()){
    int from=get<1>(checkpoint.top());
    int distance=get<0>(checkpoint.top());

    if(distance<min_distance[from]){
      min_distance[from]=distance;
      for(int i=0;i<n;i++){
        if(path[from][i]!=INT_MAX){
          checkpoint.push(make_tuple(path[from][i]+distance,i));
	}
      }
    }
    checkpoint.pop();
  }

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

C++: // ALDS1_12_B.cpp
// Graph II - Single Source Shortest Path I
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;

struct Node {
    int v;
    int c;
    Node(int v, int c): v(v), c(c) {}
};

const int maxN = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
static const int INF = (1<<21);
vector<Node> G[maxN];
vector<int> dist(maxN, INF);
vector<int> p(maxN);
vector<int> color(maxN, WHITE);
int n;
int cnt = 0;
void dijkstra(int x)
{
    dist[x] = 0;
    p[x] = -1;
    while(++cnt != n) {
        int u = 0;
        int mindist = INF;
        for (int i = 0; i < n; i++) {
            if (color[i] != BLACK && dist[i] < mindist) {
                mindist = dist[i];
                u = i;
            }
        }

        for (int i = 0; i < G[u].size(); i++) {
            if (color[u] == BLACK) continue;
            int v = G[u][i].v;
            int c = G[u][i].c;
            if (dist[u] + c < dist[v]) {
                dist[v] = dist[u] + c;
                p[v] = u;
                color[v] = GRAY;
            }
        }
        color[u] = BLACK;
    }
}

int main()
{
    cin >> n;
    int u, k;
    int v, c;
    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            cin >> v >> c;
            G[i].push_back(Node(v, c));
        }
    }
    dijkstra(0);
    for (int i = 0; i < n; i++) {
        printf("%d %d\n", i, dist[i]);
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;

int main(){
  ll n;
  cin >> n;
  vector<ll> ans(n,INFLONG);
  vector<pair<ll,ll>> vec[n];
  ll u;
  ll k;
  rep(_,n){
    cin >> u >> k;
    rep(i,k){
      cin >> t1 >> t2;
      vec[u].emplace_back(make_pair(t2,t1)); //cost , node_num
    }
  }
  priority_queue<pair<ll,ll>> pq;
  ans[0] = 0;
  for(auto itr:vec[0]){
    pq.push(make_pair(-itr.first,itr.second)); //-cost
  }
  pair<ll,ll> pa;
  while(!pq.empty()){
    pa = pq.top();
    pq.pop();
    t1 = -pa.first; //cost
    t2 = pa.second;
    //cout << t1 << " " << t2 << endl;
    if(t1 < ans[t2]){
      ans[t2] = t1;
      for(auto itr:vec[t2]){
        pq.push(make_pair(-t1 - itr.first,itr.second));
      }
    }
  }
  rep(i,n){
    cout << i << " " << ans[i] << endl;
  }
}

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 i = 0; i < vertex_num; i++){
			if (!used[i] && (vertex == -1 || d[i] < d[vertex])){
				vertex = i;
			}
		}

		// ??¨????????????????????????????¨?????????????????????´????????????????????????
		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;
}