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++: #include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <limits>
#include <cmath>
#include <numeric>
#include <string>

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
#define rep(i, a, b) for(int i = (a); i < (b); ++i )
#define rrep(i, a, b) for(int i = (a); i > (b); --i )
#define REP(i, a, b) for(int i = (a); i <= (b); ++i )
#define RREP(i, a, b) for(int i = (a); i >= (b); --i )
#define llrep(i, a, b) for(ll i = (a); i < (b); ++i )
#define llrrep(i, a, b) for(ll i = (a); i > (b); --i )
#define llREP(i, a, b) for(ll i = (a); i <= (b); ++i )
#define llRREP(i, a, b) for(ll i = (a); i >= (b); --i )
#define ullrep(i, a, b) for(ull i = (a); i < (b); ++i )
#define ullrrep(i, a, b) for(ull i = (a); i > (b); --i )
#define ullREP(i, a, b) for(ull i = (a); i <= (b); ++i )
#define ullRREP(i, a, b) for(ull i = (a); i >= (b); --i )

template<typename T=int>
class UnionFind {
public:
    explicit UnionFind(unsigned long long n) : rank_(n, 0), p_(n, 0) {
        for (T i = 0; i < n; i++) {
            MakeSet(i);
        }
    }

    void MakeSet(T x) {
        p_[x] = x;
        rank_[x] = 0;
    }

    bool Same(T x, T y) {
        return FindSet(x) == FindSet(y);
    }

    void Link(T x, T y) {
        if (rank_[x] > rank_[y]) {
            p_[y] = x;
        } else {
            p_[x] = y;
            if (rank_[x] == rank_[y]) {
                rank_[y]++;
            }
        }
    }

    void Unite(T x, T y) {
        Link(FindSet(x), FindSet(y));
    }

    T FindSet(T x) {
        if (x != p_[x]) {
            p_[x] = FindSet(p_[x]);
        }
        return p_[x];
    }

private:
    std::vector<T> rank_, p_;
};

class Dijkstra {
public:
    Dijkstra(unsigned long long num, int max_cost) :
            num_(num),
            max_cost_(max_cost),
            v_(num, std::vector<int>(num, max_cost)),
            c_(num, 0),
            d_(num, max_cost),
            p_(num, 0) {
    };

    void Compute(int start) {
        d_[start] = 0;
        p_[start] = start;
        while (true) {
            int m = -1;
            int min_d = std::numeric_limits<int>::max();
            for (int i = 0; i < num_; i++) {
                if ((c_[i] == 0) && (min_d > d_[i])) {
                    min_d = d_[i];
                    m = i;
                }
            }
            if (m < 0) {
                break;
            }
            c_[m] = 1;
            for (int i = 0; i < num_; i++) {
                if ((c_[i] == 0) && (d_[i] > (d_[m] + v_[m][i])) ) {
                    d_[i] = d_[m] + v_[m][i];
                    p_[i] = m;
                }
            }
        }
    }

public:
    int num_;
    int max_cost_;
    std::vector<std::vector<int>> v_;
    std::vector<int> c_;
    std::vector<int> d_;
    std::vector<int> p_;
};


int N, Q;

int G[100][100];
int d[100];
int p[100];
int c[100];

int main() {
    cin >> N;
//    rep(i, 0, N) {
//        rep(j, 0, N) {
//            G[i][j] = 10000010;
//        }
//    }
    Dijkstra dj(N, 10000010);
    rep(i, 0, N) {
        int u, k;
        cin >> u >> k;
        rep(j, 0, k) {
            int t, d;
            cin >> t >> d;
            dj.v_[u][t] = d;
        }
    }
    dj.Compute(0);
    rep(i, 0, N) {
        cout << i << " " << dj.d_[i] << endl;
    }
//    rep(i, 0, N) {
//        d[i] = numeric_limits<int>::max();
//    }
//
//    d[0] = 0;
//    p[0] = 0;
//    while (true) {
//        int m = -1;
//        int min_d = numeric_limits<int>::max();
//        rep(i, 0, N) {
//            if ((c[i] == 0) && (min_d > d[i])) {
//                min_d = d[i];
//                m = i;
//            }
//        }
//        if (m < 0) {
//            break;
//        }
//        c[m] = 1;
//        rep(i, 0, N) {
//            if ((d[m] + G[m][i]) < d[i]) {
//                d[i] = d[m] + G[m][i];
//                p[i] = m;
//            }
//        }
//    }
}

C++: #include <bits/stdc++.h>
#define MAX_E 1000000
#define MAX_V 100000
#define INF 1e9
typedef long long ll;
using namespace std;
/*??????????????????????????? O(V*E)*/

//??????from????????????to???????????????cost??????
struct edge{int from, to, cost;};
edge es[MAX_E]; //???
ll d[MAX_V];   //???????????¢
int V,E;        //V???????????°???E????????°

//s???????????????????????????????????????????????¢????±???????.
void Bellman_Ford(int s){
  for(int i=0; i<V ;i++) d[i]=INF;
  d[s]=0;
  while(true){
    bool update=false;
    for(int i=0; i<E ;i++){
      edge e = es[i];
      if(d[e.from] != INF && d[e.to]> d[e.from] + e.cost){
	d[e.to] = d[e.from] + e.cost;
	update = true;
      }
    }
    if(!update) break;
  }
}

//true??????????????????????????¨??????
bool find_negative_loop(){
  memset(d,0,sizeof(d));

  for(int i=0; i<V ;i++){
    for(int j=0; j<E ;j++){
      edge e = es[j];
      if(d[e.to] > d[e.from] + e.cost){
	d[e.to] = d[e.from] + e.cost;
	
	//n??????????????´??°???????????????????????????????????¨?????????
	if(i == V-1) return true;
      }
    }
  }
  return false;
}

int main(){
  cin>>V;
  for(int i=0;i<V;i++){
    int u,k;
    cin>>u>>k;
    for(int j=0,v,c;j<k;j++){
      cin>>v>>c;
      es[E++]=(edge){u,v,c};
      es[E++]=(edge){v,u,c};
  }
  }
  
  for(int i=0;i<V;i++){
    Bellman_Ford(i);
    cout <<i<<" "<<d[0]<<endl;
  }
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxx=1010;
const int infinity=1<<30;
int A[maxx][maxx],d[maxx];
bool flag[maxx];
int n,a,b,c;
	
int main (){
	cin>>n;
	for(int i=0;i<n;i++){
		flag[i]=false;
		d[i]=infinity;
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			A[i][j]=infinity;
		}
	}
	for(int i=0;i<n;i++){
		cin>>a>>b;
		for(int j=0;j<b;j++){
			cin>>c;
			cin>>A[a][c];
		}
	}
	d[0]=0;
	while(1){
		int minv=infinity,minj=-1;
		for(int i=0;i<n;i++){
			if(flag[i]==false && d[i]<minv){
				minv=d[i];
				minj=i;
			}
		}
		if(minv==infinity) break;
		flag[minj]=true;
		for(int i =0;i<n;i++){
			if(A[minj][i]!=infinity && flag[i]==false && d[i]>=d[minj]+A[minj][i]){
					d[i]=d[minj]+A[minj][i];
			}
		}
	}
	for(int i=0;i<n;i++) cout<<i<<" "<<(d[i]==infinity ? -1 : d[i])<<endl;
	
	return 0;

}