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++: #define dbg(...) fprintf(stderr,__VA_ARGS__)
#define dpr(x) cerr<<#x<<": "<<x<<endl;
#define dprc(c) do{cerr<<#c<<":";for(auto&_i:(c)){cerr<<" "<<_i;}cerr<<endl;}while(0)
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
int INF = 1e9+7;
#define all(c) (c).begin(), (c).end()
#define tr(i,c) for(auto i=(c).begin();i!=(c).end();i++)
#define rtr(i,c) for(auto i=(c).rbegin();i!=(c).rend();i++)
#define rep(i,b) for(auto i=0;i<(b);i++)
#define pb push_back
#define sz(c) int((c).size())

int main(int argc, char **argv)
{
  int n;
  scanf("%d", &n);

  vector<vector<pii>> G(n, vector<pii>());
  for (int i = 0; i < n; i++) {
    int u, k, v, c;
    scanf("%d %d", &u, &k);
    for (int j = 0; j < k; j++) {
      scanf("%d %d", &v, &c);
      G[u].pb(pii(v, c));
    }
  }

  vi d(n, INF);
  vector<bool> visited(n, false);
  int vc = 0;
  priority_queue<pii, vector<pii>, greater<pii>> q;

  d[0] = 0;
  visited[0] = true;
  vc = 1;
  q.push(pii(0, 0));
  
  while(!q.empty()) {
    pii p = q.top(); q.pop();
    int u = p.second;

    if (d[u] < p.first) continue;

    visited[u] = true;
    for (auto e:G[u]) {
      int v = e.first;
      int c = e.second;
      if (!visited[v] && (d[u] + c < d[v])) {
        d[v] = d[u] + c;
        q.push(pii(d[v], v));
      }
    }
  }

  for (int i = 0; i < n; i++) {
    printf("%d %d\n", i, d[i]);
  }

  return 0;
}

C++: #include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<list>
#include<stack>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

const int MAX = 100;


enum col
  {
   WHITE = 0,
   GRAY =  1,
   BLACK = 2,
  };

using namespace std;
const int INF = 0x7fffffff;

int M[MAX][MAX];
col color[MAX];
int d[MAX];
int p[MAX];
int n;

void daikusutora(int s){
  int ii,vv;

  //初期化
  for(ii=0;ii<n;ii++){
    color[ii] = WHITE;
    d[ii] = INF;
    p[ii] = -1;
  }
  
  d[s] = 0;
  p[s] = -1;
  
  int mincost,u;
  while(1){
    mincost = INF;
    u = -1;

    //次に選ぶ頂点の決定
    for(ii=0;ii<n;ii++){
      if(color[ii] != BLACK && d[ii] < mincost){

        mincost = d[ii];
        u = ii;
        //cout << "u:" << u << endl;
      }
    }

    //ループの終了条件
    if(mincost == INF){
      break;
    }

    color[u] = BLACK;
    //cout << "color:" << u << endl;

    //次のパスの選択候補
    for(vv=0;vv<n;vv++){
      //未探索の頂点かつ u -> vv へのパスがある場合
      if(color[vv] != BLACK && M[u][vv] != INF){
        //次に探索する候補
        if(d[u] + M[u][vv] < d[vv]){
          //cout << "vv:" << vv << endl;
          d[vv] = d[u] + M[u][vv];
          //color[vv] = GRAY;
        }
      }
    }
    
  }
  
}

int main(){

  long ii,jj,kk;
  int u,k,v,c;
  vector<int> a;

  cin >> n;

  //初期化
  for(ii=0;ii<n;ii++){
    for(jj=0;jj<n;jj++){
      M[ii][jj] = INF;
    }
  }
  
  for(ii=0;ii<n;ii++){

    cin >> u >> k;
    //cout << "u:" << u << "k:" << k << endl;
    for(jj=0;jj<k;jj++){
      cin >> v >> c;
      M[ii][v] = c;
    }
    
  }

  //for(ii=0;ii<n;ii++){
  //  for(jj=0;jj<n;jj++){
  //    cout << M[ii][jj] << " " ;
  //  }
  //  cout << endl;
  //}

  daikusutora(0);

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

C++: #include<iostream>
#include<cstdio>
#define INF 200001 
using namespace std;
int n;
int A[1000][1000];
int D[1000][1000];
  
void Init(int f){
  for(int i=0;i<f;i++){
    for(int j=0;j<f;j++)D[i][j] = INF;
  } 
}
  
int main(){
  scanf("%d",&n);
  int u,k,C,V;
  Init(n);
   
  for(int i=0;i<n;i++){
      scanf("%d %d",&u,&k);    
      for(int j=0;j<k;j++){
    scanf("%d %d",&V,&C);
    D[u][V] = C;
    
      }    
  }
  for(int i=0;i<n;i++)D[i][i] = 0;
 
  for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++)D[i][j]= min(D[i][j],D[i][k] + D[k][j]);
 
  for(int i=0;i<n;i++)printf("%d %d\n",i,D[0][i]);
  
  
  return 0;
}