Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

var infty = 1000000000

type DirectedGraphNodeID int

type DirectedGraphNode struct {
	key         DirectedGraphNodeID
	adjacents   []*DirectedGraphNode
	costs       []int
	distance    int
	predecessor *DirectedGraphNode
}

func newDirectedGraph(nNodes int) *DirectedGraph {
	graph := DirectedGraph{}
	graph.nodes = make([]*DirectedGraphNode, nNodes)
	for i := 0; i < nNodes; i++ {
		node := DirectedGraphNode{}
		node.key = DirectedGraphNodeID(i)
		node.distance = infty
		graph.nodes[i] = &node
	}
	return &graph
}

type DirectedGraph struct {
	nodes []*DirectedGraphNode
}

func (g *DirectedGraph) setAdjacency(i, j DirectedGraphNodeID, cost int) {
	g.nodes[i].adjacents = append(g.nodes[i].adjacents, g.nodes[j])
	g.nodes[i].costs = append(g.nodes[i].costs, cost)
}

func (g *DirectedGraph) print() {
	for i := 0; i < len(g.nodes); i++ {
		node := g.nodes[i]
		key := node.key
		strings := []string{strconv.Itoa(int(key)), strconv.Itoa(node.distance)}
		for j := 0; j < len(node.adjacents); j++ {
			nodeJ := fmt.Sprintf("(%v, %v)", node.adjacents[j].key, node.costs[j])
			strings = append(strings, nodeJ)
		}
		fmt.Printf("%v\n", strings)
	}
}

func (g *DirectedGraph) relaxEdge(l, r *DirectedGraphNode, w int) {
	if r.distance > l.distance+w {
		// fmt.Printf("%v -> %v, %v\n", l.key, r.key, l.distance+w)
		r.distance = l.distance + w
		r.predecessor = l
	}
}

func main() {
	scanner.Split(bufio.ScanWords)

	nNodes := nextInt()
	graph := newDirectedGraph(nNodes)

	for i := 0; i < nNodes; i++ {
		iNode := DirectedGraphNodeID(nextInt())
		nAdjacent := nextInt()
		for j := 0; j < nAdjacent; j++ {
			jNode := DirectedGraphNodeID(nextInt())
			cost := nextInt()
			graph.setAdjacency(iNode, jNode, cost)
		}
	}

	graph.nodes[0].distance = 0
	for iNode := 0; iNode < nNodes; iNode++ {
		for iLeft := 0; iLeft < len(graph.nodes); iLeft++ {
			nodeLeft := graph.nodes[iLeft]
			for iRight := 0; iRight < len(nodeLeft.adjacents); iRight++ {
				nodeRight := nodeLeft.adjacents[iRight]
				cost := nodeLeft.costs[iRight]
				graph.relaxEdge(nodeLeft, nodeRight, cost)
			}
		}
	}

	// graph.print()

	for iNode := 0; iNode < len(graph.nodes); iNode++ {
		node := graph.nodes[iNode]
		fmt.Println(node.key, node.distance)
	}
}

C++: #include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
typedef long long ll;

int M[100][100];

int main()
{
	int n;cin >> n;
	rep(i,n)
		rep(j,n)M[i][j]=INT_MAX;
		
	rep(i,n)
	{
		int hoge, hogege;
		cin >> hoge >> hogege;
		rep(j,hogege)
		{
			int foo,fooo;
			cin >> foo >> fooo;
			M[i][foo]=fooo;
		}
	}

	vector<int> color(n);
	rep(i,n)color[i]=0;
	vector<int> d(n);
	rep(i,n)d[i]=INT_MAX;
	vector<int> p(n);
	d[0]=0;
	p[0]=-1;

	while (1)
	{
		int u;
		int mincost = INT_MAX;
		rep(i,n)
		{
			if((color[i]!=2)&&(d[i]<mincost))
			{
				mincost=d[i];
				u=i;
			}
		}

		if(mincost==INT_MAX)break;

		color[u] = 2;

		rep(v,n)
		{
			if(color[v] != 2&&M[u][v]!=INT_MAX)
			{
				if(d[u] + M[u][v] < d[v])
				{
					d[v] = d[u] + M[u][v];
					p[v] = u;
					color[v] = 1;
				}
			}
		}
	}
	rep(i,n)
	{
		cout<<i<<" "<<d[i]<<endl;
	}


	

	return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const long long INF = 1LL << 60;    // 1.15x10^18
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using edge = pair<int, long long>;
using Graph = vector<vector<edge>>;

vector<long long> dijkstra(const Graph &g, int s) {
    int n = g.size();
    vector<long long> dist(n, INF);
    vector<bool> fixed(n);
    dist[s] = 0;
    while (true) {
        int u = -1;
        for (int i = 0; i < n; i++) if (!fixed[i]) {
            if (u == -1 || dist[i] < dist[u]) u = i;
        }
        if (u == -1) break;
        fixed[u] = true;
        for (auto &e: g[u]) chmin(dist[e.first], dist[u] + e.second);
    }
    return dist;
}

int main() {
    int V; cin >> V;
    Graph g(V);
    for (int i = 0; i < V; i++) {
        int u, k; cin >> u >> k;
        while (k--) {
            int v, c; cin >> v >> c;
            g[u].emplace_back(v, c);
        }
    }
    auto dist = dijkstra(g, 0);
    for (int u = 0; u < V; u++) cout << u << " " << dist[u] << endl;
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;
int inf = 1000000000;

class UF{
public:
  vector<int> u;
  vector<int> r;

  void init(int n){
    u.resize(n, 0);
    r.resize(n, 0);
    for(int i=0; i<n; i++) u[i] = i;
  }
  int root(int x){
    // if( u[x] == x ) return x;
    // else return root(u[x]);
    return u[x] == x ? x : u[x] = root(u[x]);
  }
  bool same(int x, int y){
    return root(x) == root(y);
  }
  void unite(int x, int y){
    x = root(x);
    y = root(y);
    if( x == y ) return;

    if( r[x] < r[y] ){
      u[x] = y;
    }else{
      u[y] = x;
      if( r[x] == r[y] ) r[x]++;
    }
  }
};
class Graph{
public:
  int from, to, cost;
  bool operator<(const Graph &g1)const{
    return g1.cost < cost;
  };
};

int main(void) {

  int n;
  cin >> n;
  UF uf;
  uf.init(n);
  priority_queue<Graph> g;

  vector< vector<int> > d(n, vector<int> (n, inf));

  for(int i=0; i<n; i++){
    d[i][i] = 0;
    int u, k;
    cin >> u >> k;
    for(int j=0; j<k; j++){
      int c, v;
      cin >> v >> c;
      d[u][v] = min(c, d[u][v]);
      // Graph tg;
      // tg.to = v;
      // tg.from = u;
      // tg.cost = c;
      // g.push(tg);
    }
  }
  while( !g.empty() ){
    cerr << g.top().from << " " << g.top().to << " " << g.top().cost << endl;
    g.pop();
  }

  for(int i=0; i<n; i++){
    for(int j=0; j<n; j++){
      for(int k=0; k<n; k++){
        d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
      }
    }
  }

  for(int i=0; i<n; i++){
    cout << i << " " << d[0][i] << endl;
  }

  return 0;
}

// EOF