Go: package main

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

func main() {
	r := bufio.NewReader(os.Stdin)

	var n int
	fmt.Fscan(r, &n)
	cs := make([]map[int]int, n) // []v_i -> c_i
	for h := 0; h < n; h++ {
		var u, k int
		fmt.Fscan(r, &u, &k)
		m := make(map[int]int)
		for i := 0; i < k; i++ {
			var v, c int
			fmt.Fscan(r, &v, &c)
			m[v] = c
		}

		cs[u] = m
	}

	q := make(map[int]int)
	q[0] = 0
	visited := make(map[int]struct{})
	out := make([]int, n)

	for len(q) > 0 {
		u := top(q)
		for uu, c := range cs[u] {
			// Consider the connection between u and uu.
			if _, ok := visited[uu]; ok {
				continue
			}
			if d, ok := q[uu]; !ok || d > q[u]+c {
				q[uu] = q[u] + c
			}
		}

		out[u] = q[u]
		delete(q, u)
		visited[u] = struct{}{}
	}

	for u, d := range out {
		fmt.Println(u, d)
	}
}

func top(q map[int]int) int {
	minu := -1
	min := -1
	for u, d := range q {
		if min < 0 || d < min {
			minu = u
			min = d
		}
	}

	return minu
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<stack>
using namespace std;
#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INFTY (1<<30)
int n,M[MAX][MAX];

void dijkstra()
{
  int minv;
  int d[MAX],color[MAX];
  
  for(int i=0;i<n;i++)
    {
      d[i]=INFTY;
      color[i]=WHITE;
    }
  d[0] = 0;
  color[0]=GRAY;
  while(1)
    {
      minv=INFTY;
      int u=-1;
      for(int i=0;i<n;i++)
	{
	  if(minv > d[i] && color[i] !=BLACK)
	    {
	      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)
	    {
	      if(d[v] > d[u] + M[u][v] )
		{
		  d[v] = d[u]+M[u][v];
		  color[v]=GRAY;
		}
	    }
	}
    }
  for( int i=0;i<n;i++)
    {
      cout << i << " " << (d[i]==INFTY ? -1: d[i] ) << endl;
    }
}

int main(){
  cin >> n;
  for(int i=0;i<n;i++)
    {
      for(int j=0;j<n;j++)
	{
	  M[i][j]=INFTY;
	}
    }
  int k,c,u,v;
  for(int i=0; i<n; i++)
    {
      cin >> u >> k;
      for(int j=0;j<k;j++)
	{
	  cin >> v >> c;
	  M[u][v]=c;
	}
    }
  dijkstra();
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
using ll = long long;

// #undef DEBUG
#define DEBUG
/// {{{ DEBUG --- ///
#ifdef DEBUG
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { o << "{"; for(size_t i = 0; i < v.size(); i++) o << v[i] << (i + 1 != v.size() ? ", " : ""); o << "}"; return o; }
#ifdef USE_COUT
#define dump(...) [&](){auto __debug_tap=make_tuple(__VA_ARGS__);cout<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<__debug_tap<<"\n";}()
#else
#define dump(...) [&](){auto __debug_tap=make_tuple(__VA_ARGS__);cerr<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<__debug_tap<<"\n";}()
#endif
template<class T> inline void dump2D(T &d, size_t sizey, size_t sizex) { ostream&o=
#ifdef USE_COUT
  cout;
#else
  cerr;
#endif
  for(size_t i = 0; i < sizey; i++) { for(size_t j = 0; j < sizex; j++) o << d[i][j] << " "; o << endl; }
}
#else
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { for(size_t i = 0; i < v.size(); i++) o << v[i] << (i + 1 != v.size() ? " " : ""); return o; }
#define dump(...) (42)
#define dump2D(...) (42)
#endif
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":", ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream &o, tuple<T...> const &t){ o << "("; _ot<0>(o, t); o << ")"; return o; }
template<class T, class U> ostream & operator<<(ostream &o, pair<T, U> const &p) { o << "(" << p.first << ", " << p.second << ")"; return o; }
/// }}}--- ///

template<class T = int, class U = uint64_t>
struct RadixHeap {
private:
  std::vector< pair<U, T> > v[sizeof(U) * 8 + 1];
  std::size_t sz = 0;
  U last = 0;
  std::size_t logbinll(U x) {
    std::size_t h = 0;
    x = x & 0xFFFFFFFF00000000 ? (h += 32, x) & 0xFFFFFFFF00000000 : x;
    x = x & 0xFFFF0000FFFF0000 ? (h += 16, x) & 0xFFFF0000FFFF0000 : x;
    x = x & 0xFF00FF00FF00FF00 ? (h += 8, x) & 0xFF00FF00FF00FF00 : x;
    x = x & 0xF0F0F0F0F0F0F0F0 ? (h += 4, x) & 0xF0F0F0F0F0F0F0F0 : x;
    x = x & 0xCCCCCCCCCCCCCCCC ? (h += 2, x) & 0xCCCCCCCCCCCCCCCC : x;
    x = x & 0xAAAAAAAAAAAAAAAA ? (h += 1, x) & 0xAAAAAAAAAAAAAAAA : x;
    return h;
  }
public:
  void push(U x, T y) {
    // assert(last <= f(x));
    v[logbinll(x^last)].emplace_back(x, y);
    sz++;
  }
  pair<U, T> pop() {
    // assert(sz);
    if(!v[0].size()) {
      std::size_t i = 1;
      while(!v[i].size()) i++;
      last = min_element(begin(v[i]), end(v[i]))->first;
      for(const pair<U, T> & e : v[i])
        v[logbinll(e.first ^ last)].emplace_back(e);
      v[i].clear();
    }
    sz--;
    pair<U, T> res = v[0].back();
    v[0].pop_back();
    return res;
  }
  std::size_t size() { return sz; }
};

vector<pair<int, int>> g[100];
int n;
int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  cin >> n;
  for(int i = 0; i < n; i++) {
    int x, m;
    cin >> x >> m;
    while(m--) {
      int t, c;
      cin >> t >> c;
      g[x].emplace_back(t, c);
    }
  }
  // dijkstra {{{
  vector<ll> dist(n, 1e18);
  RadixHeap<int> rh;
  rh.push(0, 0);
  dist[0] = 0;
  while(rh.size()) {
    ll di; int i;
    tie(di, i) = rh.pop();
    if(dist[i] < di) continue;
    for(auto to : g[i]) {
      int j = to.first;
      ll ndi = di + to.second;
      if(dist[j] > ndi) {
        dist[j] = ndi;
        rh.push(ndi, j);
      }
    }
  }
  // }}}
  for(int i = 0; i < n; i++)cout << i << " "<< dist[i] << endl;
  return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
const int SIZE=200001+5000;
//int arr[SIZE]={};
//???????????§???????????¬
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(auto i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;
void shortestPath(const Graph &g, int s,
    vector<Weight> &dist, vector<int> &prev) {
  int n = g.size();
  dist.assign(n, INF); dist[s] = 0;
  prev.assign(n, -1);
  priority_queue<Edge> Q; // "e < f" <=> "e.weight > f.weight"
  for (Q.push(Edge(-2, s, 0)); !Q.empty(); ) {
    Edge e = Q.top(); Q.pop();
    if (prev[e.dst] != -1) continue;
    prev[e.dst] = e.src;
    FOR(f,g[e.dst]) {
      if (dist[f->dst] > e.weight+f->weight) {
        dist[f->dst] = e.weight+f->weight;
        Q.push(Edge(f->src, f->dst, e.weight+f->weight));
      }
    }
  }
}
vector<int> buildPath(const vector<int> &prev, int t) {
  vector<int> path;
  for (int u = t; u >= 0; u = prev[u])
    path.push_back(u);
  reverse(path.begin(), path.end());
  return path;
}
int main(){
	Graph G;
	int N;
	cin>>N;
	for(int i=0;i<N;i++){
		Edges E;
		G.push_back(E);
	}
	for(int i=0;i<N;i++){
		int u,k;
		cin>>u>>k;
		for(int j=0;j<k;j++){
			int v,c;
			cin>>v>>c;
			G[u].push_back(Edge(u,v,c));
		}
	}
	vector<Weight> dist;
	vector<int> prev;
	shortestPath(G,0,dist,prev);
	for(int i=0;i<N;i++){
		cout<<i<<" "<<dist[i]<<endl;
	}
	return 0;
}