Go: package main

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

const (
	white int = iota
	gray
	black
)

type node struct {
	id     int
	parent int
	edge   []int
	weight []int
	color  int
}

type graph struct {
	nodes    []node
	distance []int
}

var infty = 1 << 32
var null = -1

func constructgraph() *graph {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)

	g := &graph{make([]node, n), make([]int, n)}

	for i := 0; i < n; i++ {
		id := nextInt(sc)
		edges := nextInt(sc)
		n := node{}
		n.id = id
		n.edge = make([]int, edges)
		n.weight = make([]int, edges)
		n.color = white
		for j := 0; j < edges; j++ {
			to := nextInt(sc)
			w := nextInt(sc)
			n.edge[j] = to
			n.weight[j] = w
		}
		g.nodes[id] = n
	}
	return g
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func (g *graph) preparedijkstra(s int) {
	for i := 0; i < len(g.nodes); i++ {
		g.nodes[i].color = white
		g.nodes[i].parent = null
		g.distance[i] = infty
	}
	g.distance[s] = 0
}

func (g *graph) dijkstra(s int) []int {
	g.preparedijkstra(s)

	for {
		var u int
		mincost := infty
		for i, d := range g.distance {
			if g.nodes[i].color != black && mincost > d {
				mincost = d
				u = i
			}
		}

		if mincost == infty {
			break
		}

		g.nodes[u].color = black

		for i, e := range g.nodes[u].edge {
			if g.nodes[e].color != black {
				if g.distance[e] > g.distance[u]+g.nodes[u].weight[i] {
					g.distance[e] = g.distance[u] + g.nodes[u].weight[i]
					g.nodes[e].parent = u
					g.nodes[e].color = gray
				}
			}
		}
	}
	return g.distance
}

func printShortestPath(d []int) {
	for i, v := range d {
		fmt.Printf("%d %d\n", i, v)
	}
}

func main() {
	g := constructgraph()
	d := g.dijkstra(0)
	printShortestPath(d)
}

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;
}