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 <cstdio>
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, **M;
int *d, *p;

void dijkstra() {
    int u, minv;
    int d[n], p[n], color[n];

    for (int i = 0; i < n; i++) {
        d[i] = INFTY;
        p[i] = -1;
        color[n] = WHITE;
    }
    d[0] = 0;

    while (1) {
        u = -1;
        minv = INFTY;
        for (int i = 0; i < n; i++) {
            if (color[i] != BLACK && d[i] < minv) {
                u = i;
                minv = d[i];
            }
        }

        if (u == -1) { break; }

        color[u] = BLACK;
        for (int v = 0; v < n; v++) {
            if (color[v] != BLACK && M[u][v] != INFTY) {
                // printf("d[%d] = %d, M[%d][%d] = %d, d[%d] = %d\n", u, d[u], u, v, M[u][v], v, d[v]);
                if (d[u] + M[u][v] < d[v]) {
                    p[v] = u;
                    d[v] = d[u] + M[u][v];
                    color[v] = GRAY;
                }             
            }
        }
    }
    
    for (int i = 0; i < n; i++) {
        printf("%d %d\n", i, d[i]);
    }
}

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

    M = new int*[n];
    for (int i = 0; i < n; i++) {
        M[i] = new int[n];
        for (int j = 0; j < n; j++) {
            M[i][j] = INFTY;
        }
    }

    for (int i = 0; i < n; i++) {
        int u, k;
        scanf("%d %d", &u, &k);
        for (int j = 0; j < k; j++) {
            int v, c;
            scanf("%d %d", &v, &c);
            M[u][v] = c;
        }
    }
    printf("");

    dijkstra();

    return 0;
}

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

struct edge {int to, cost; };
using P = pair<int , int>;
int V;
vector <edge> G[100010];
int d[100010];

void dijkstrra(int s){
    priority_queue <P, vector<P>, greater<P> > que;
    fill(d, d + V, 1000000000);
    d[s] = 0;
    que.push(P(0 , s));
    
    while(!que.empty()){
        P p = que.top(); que.pop();
        int v = p.second;
        if(d[v] < p.first)  continue;
        for(int i = 0; i < G[v].size(); i++){
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main(){
    int n;
    cin >> n;
    V = n;
    for(int i = 0; i < n; i++){
        int u, k;
        cin >> u >> k;
        int v,c;
        for(int i = 0; i < k; i++){
            cin >> v >> c;
            G[u].push_back(edge{v, c});
        }
    }
    dijkstrra(0);
    for(int i = 0; i < n; i++)
        cout << i << " " << d[i] << endl;
    return 0;
}

C++: // #include {{{
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <tuple>
#include <utility>
#include <random>
#include <limits>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>
// }}}

using namespace std;

// macros {{{
template<typename T, size_t N>
constexpr size_t NELEMS(T (&)[N]) { return N; }

template<typename InputIt>
void PRINT_RANGE(InputIt first, InputIt last)
{
    for(; first != last; ++first)
        cout << *first << (first==last ? "" : " ");
    cout << "\n";
}

template<typename T>
void PRINT_MATRIX(T mat, size_t nr, size_t nc)
{
    for(size_t r = 0; r < nr; ++r) {
        for(size_t c = 0; c < nc; ++c) {
            cout << mat[r][c] << (c==nc-1 ? "" : " ");
        }
        cout << "\n";
    }
}

#define FOR(i, start, end) for(int i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)
// }}}

// types {{{
using ll  = long long;
using ull = unsigned long long;
// }}}

struct Edge {
    int to;
    int cost;
    Edge(int t, int c) : to(t), cost(c) {}
};

constexpr int INF = numeric_limits<int>::max();

int N;
vector<vector<Edge>> G;

/**
 * ???????§???????????????? Bellman-Ford???
 *
 * \return ???????????????????????° true, ????????° false
 */
bool bellmanford(int start, vector<int>& d)
{
    d.resize(N);
    fill(begin(d), end(d), INF);
    d[start] = 0;

    REP(i, N) {
        REP(v, N) {
            if(d[v] == INF) continue;
            for(Edge e : G[v]) {
                int cost_new = d[v] + e.cost;
                if(cost_new < d[e.to]) {
                    d[e.to] = cost_new;
                    if(i == N-1) return false;
                }
            }
        }
    }

    return true;
}

void solve()
{
    vector<int> d;
    bellmanford(0, d);

    REP(i, N) {
        cout << i << " " << d[i] << "\n";
    }
}

int main()
{
    cin >> N;
    G.resize(N);

    REP(_, N) {
        int from, k;
        cin >> from >> k;
        REP(_, k) {
            int to, cost;
            cin >> to >> cost;
            G[from].emplace_back(to, cost);
        }
    }

    solve();

    return 0;
}

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

C++: #include<iostream>
#include<queue>
#include<algorithm>
#include<cstring>

using namespace std;

typedef pair<int,int>pii;
#define INF 0x3f3f3f3f
#define fi first
#define se second

int mcos[105];
vector <pii> G[105];
int N;


void dijkstra(int start){
  priority_queue<pii,vector<pii>,greater<pii> > pq;

  pq.push( pii(0,start) );
  memset( mcos,INF,sizeof(mcos));
  mcos[start]=0;

  
  while(!pq.empty() ){
    const pii tmp=pq.top();
    pq.pop();
    
    const int now=tmp.se;
    
    if(mcos[now] < tmp.fi) continue;
    
    for(int i=0;i<G[now].size();++i){
      const int newcost = G[now][i].fi + tmp.fi;
      const int next= G[now][i].se;
      
      if(newcost < mcos[next] ){
	mcos[next]=newcost;
	pq.push( pii(newcost,next) );
      }
    }
  }
  return ;
  
}

int main (){
  cin>>N;
  int k,u,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(make_pair(c,v));
    }
  }
  dijkstra(0);
  for(int i=0;i<N;i++){
    cout<<i<<" "<<mcos[i]<<endl;
  }
  return 0;
}