Go: package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
type Node struct {
	cost int
	done bool
}

type Edge struct {
	to, cost int
}

const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	nodes := make([]Node, N)
	for i := 0; i < N; i++ {
		nodes[i].cost = INF
	}
	E := make([][]Edge, N)
	for i := 0; i < N; i++ {
		id, k := sc.nextInt(), sc.nextInt()
		for j := 0; j < k; j++ {
			to, cost := sc.nextInt(), sc.nextInt()
			E[id] = append(E[id], Edge{to, cost})
		}
	}
	nodes[0].cost = 0
	for {
		cur := 0
		minCost := INF
		for i := 0; i < N; i++ {
			n := nodes[i]
			if !n.done && n.cost < minCost {
				cur = i
				minCost = n.cost
			}
		}
		if minCost == INF {
			break
		}
		nodes[cur].done = true
		for i := 0; i < len(E[cur]); i++ {
			to, cost := E[cur][i].to, E[cur][i].cost+nodes[cur].cost
			if !nodes[to].done && cost < nodes[to].cost {
				nodes[to].cost = cost
			}
		}
	}

	for i := 0; i < N; i++ {
		fmt.Fprintln(wtr, i, nodes[i].cost)
	}
	wtr.Flush()
}

C++: #include <vector>
#include <cassert>

using size_t = std::size_t;

template<class id_type>
class Graph{
public:
  using vertex_type = size_t;
  struct Edge{
    vertex_type to;
    id_type id;
  };

  struct Edge_Pair{
    vertex_type from;
    vertex_type to;
    id_type id;
  };
private:
  std::vector<vertex_type> ver;
  std::vector<Edge_Pair> edges;
  std::vector<std::vector<Edge>> G;
  std::vector<std::vector<Edge>> rG;
public:
  Graph(size_t sz) : ver(sz) , G(sz) , rG(sz){
    for(size_t i = 0;i < ver.size();i++) ver[i] = i;
  }

  const std::vector<vertex_type>& V() const{
    return ver;
  }

  const std::vector<Edge_Pair>& E() const{
    return edges;
  }

  void add_edge(const Edge_Pair& e){
    edges.push_back(e);
    G[e.from].push_back({e.to,e.id});
    rG[e.to].push_back({e.from,e.id});
  }

  void add_edge(vertex_type from,vertex_type to,id_type id){
    add_edge({from,to,id});
  }

  Graph operator+=(const Edge_Pair& e){
    add_edge(e);
    return *this;
  }


  const std::vector<Edge>& delta_p(vertex_type v) const{
    return G[v];
  }

  const std::vector<Edge>& delta_m(vertex_type v) const{
    return rG[v];
  }

  const std::vector<Edge>& operator[](vertex_type v) const{
    return this->delta_p(v);
  }
};

#include <set>
#include <queue>
#include <functional>

template<class dist_type,class id_type>
std::vector<dist_type> dijkstra(const Graph<id_type>& g,std::function<dist_type(id_type)> cost,size_t s,dist_type init,dist_type INF){
    using vt = typename Graph<id_type>::vertex_type;
    using P = std::pair<dist_type,vt>;
    std::vector<dist_type> dist(g.V().size(),INF);
    dist[s] = init;

    std::priority_queue<P,std::vector<P>,std::greater<P>> que;

    que.push({dist[s],s});

    while(!que.empty()){
      vt v = que.top().second;
      dist_type d = que.top().first;
      que.pop();
      if(dist[v] < d) continue;
      for(const auto & e : g.delta_p(v)){
        if(dist[e.to] > dist[v] + cost(e.id)){
          dist[e.to] = dist[v] + cost(e.id);
          que.push({dist[e.to],e.to});
        }
      }
    }

    return dist;
}

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int main(){
  int n;
  cin >> n;
  Graph<size_t> g(n);
  vector<i64> cost;
  for(int i = 0;i < n;i++){
    size_t u,t;
    cin >> u >> t;
    for(int j = 0;j < t;j++){
      size_t v;
      i64 c;
      cin >> v >> c;
      g.add_edge(u,v,cost.size());
      cost.push_back(c);
    }
  }

  auto res = dijkstra<i64,size_t>(g,[&](size_t id)->i64{return cost[id];},0UL,0LL,(i64)1e9);
  for(int i = 0;i < n;i++){
    cout << i << " " << res[i] << endl;
  }
}

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

constexpr long long inf = numeric_limits<long long>::max()/10;
struct edge{
    long long to,cost;
    edge(){}
    edge(long long to_,long long cost_) : to(to_),cost(cost_){}
};

vector<long long> dijkstra(int s,const vector<vector<edge>>& g){
    using P = pair<long long,long long>;
    long long V = g.size();
    vector<long long> d(V,inf);
    priority_queue<P,vector<P>,greater<P>> que;
    d[s] = 0;
    que.push(P(0,s));
    while(!que.empty()){
        P p=que.top();que.pop();
        long long 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));
            }
        }
    }
    return d;
}

int main(){
    int n;
    cin>>n;
    vector<vector<edge>> g(n);
    for(int i=0;i<n;i++){
        int u,k;
        cin>>u>>k;
        for(int j=0;j<k;j++){
            long long v,c;
            cin>>v>>c;
            g[u].push_back(edge(v,c));
        }
    }
    auto dist = dijkstra(0,g);
    for(int i=0;i<n;i++){
        cout << i << " " << dist[i] << endl;
    }
}

C++: #include <iostream>
#include <vector>
#include <climits>
using namespace std;

vector< vector< int > > adjMatrix;

vector< int > findCostsFrom0(int n) {
  int nvisited = 1;
  vector< int > cost (n, INT_MAX);
  cost[0] = 0;
  while (nvisited < n) {
    int toadd = -1;
    int toaddcost = INT_MAX;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
	if ((cost[i] != INT_MAX) &&
	    (cost[j] == INT_MAX) &&
	    (cost[i] + adjMatrix[i][j] < toaddcost)) {
	  toaddcost = cost[i] + adjMatrix[i][j];
	  toadd = j;
	  // cout << toadd << ' ' << toaddcost << endl;
	}
      }
    }
    nvisited++;
    cost[toadd] = toaddcost;
  }
  return cost;
}

int main(int argc, char **argv) {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  adjMatrix = vector< vector< int > > (n, vector< int > (n, INT_MAX/2));
  for (int i = 0; i < n; i++) {
    adjMatrix[i][i] = 0;
    int u, k;
    cin >> u >> k;
    for (int j = 0; j < k; j++) {
      int vj;
      cin >> vj;
      cin >> adjMatrix[u][vj];
    }
  }
  vector< int > costs = findCostsFrom0(n);
  for (int i = 0; i < n; i++)
    cout << i << ' ' << costs[i] << endl;
  return 0;
}