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<stdio.h>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<queue>
#include<functional>
using namespace std;
int main(){
	int a;
	int b;
	int s;
	int t;
	vector<int> n[10000];
	int nn[10000];
	vector<int> x[10000];
	priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > >y;
	vector<pair<int, int> >::iterator yy;
	int z;
	int d[10000];
	int e;
	int c[10000];
	int zz;
	pair<int, int>pai;
	for (int i = 0; i < 10000; i++){
		d[i] = 1000000009;
		c[i] = 0;
	}
	scanf("%d", &a);
	for (int i = 0; i < a; i++){
		scanf("%d %d", &s, &b);
		for (int j = 0; j < b; j++){
			scanf("%d %d", &t, &e);
			n[s].push_back(t);
			nn[s]++;
			x[s].push_back(e);

		}
	}
	d[0] = 0;
	y.push(std::make_pair(d[0], 0));
	for (int i = 0; y.empty() == 0; i++){
		zz = 0;
		for (int j = 0; y.empty() == 0 && zz == 0; j++){
			pai = y.top();
			z = pai.second;
			if (c[z] == 0)zz++;
			else y.pop();
		}
		if (zz == 0)break;
		c[z] = 1;
		for (int j = 0; j < nn[z]; j++){
			if (d[z] + x[z][j] < d[n[z][j]])
			{
				d[n[z][j]] = d[z] + x[z][j];
				y.push(std::make_pair(d[n[z][j]], n[z][j]));
			}
		}
		y.pop();
	}
	for (int i = 0; i<a; i++)printf("%d %d\n",i,d[i]);
		return 0;
}

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

static const int MAX =100;
static const int INF=(1<<21);
static const int WHITE =0;
static const int GRAY =1;
static const int BRACK =2;

int n,A[MAX][MAX];

void dij(){
  int minv,d[MAX],c[MAX];

  for(int i=0;i<n;i++){
    d[i]=INF;
   
    c[i]=WHITE;
  }

  d[0]=0;
  c[0]=GRAY;
  
  while(1){
    minv=INF;
    int x=-1;
    for(int i=0;i<n;i++){
      if(minv>d[i] && c[i]!=BRACK){
	x=i;
	minv=d[i];
      }
    }
    if(x==-1)break;
    c[x]=BRACK;
    for(int v=0;v<n;v++){
      if(c[v]!=BRACK && A[x][v]!=INF){
	if(d[v]>d[x]+A[x][v]){
	  d[v]=d[x]+A[x][v];
	 
	  c[v]=GRAY;
	}
      }
    }
  }
  for(int i=0;i<n;i++){
    cout<<i<<" "<<(d[i]==INF ? -1: d[i])<<endl;
  }
}
 

int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      A[i][j]=INF;
    }
  }
  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;
      A[u][v]=c;
    }
  }
  dij();
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define pb push_back
#define fi first
#define se second

#define MAX_V 110
#define INF 1e9

struct edge{int to,cost;};
typedef pair<int,int> P;
int d[MAX_V];
int V;
vector<edge> G[MAX_V];

edge makeedge(int t,int c){
    edge e;
    e.to=t;
    e.cost=c;
    return e;
}

void addedge(int s,int t,int c){
    G[s].push_back(makeedge(t,c));
    //G[t].push_back(makeedge(s,cost));
}

void dijkstra(int s){
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d,d+V,INF);
    d[s]=0;
    que.push(P(0,s)); 

    while(!que.empty()){
        P p=que.top(); que.pop();
        int 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));
            }
        }
    }
}


int main(){
    int i,j,n;
    cin>>n;
    V=n;
    int u,k;
    int x,y;
    for(i=0;i<n;i++){
        cin>>u>>k;
        for(j=0;j<k;j++){
            cin>>x>>y;
            addedge(i,x,y);
        }
    }
    dijkstra(0);
    for(i=0;i<n;i++){
        cout<<i<<" "<<d[i]<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <sstream>
#include <string>
#include <utility>
#include <map>
#include <memory>
#include <set>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>

using namespace std;

class SSSPath
{
public:
  vector<int> v;
  int solve();
};

int SSSPath::solve()
{
  int n;
  cin >> n;

  const int infty = 20000;
  vector<int> d( n, infty );
  
  d[0] = 0;

  vector<vector<int>> adj( n, vector<int>( n, -1 ) );


  for ( auto i = 0; i < n; ++i )
    {
      int u, v, k, c;
      cin >> u >> k;
      for ( auto j = 0; j < k; ++j )
        {
          cin >> v >> c;
          adj[u][v] = c;
        }
    }

  vector<int> sv( n, true );

  while ( true )
    {
      int md = infty;
      int u;
      
      for ( auto i = 0; i < n; ++i )
        {
          if ( sv[i] && d[i] < md )
            {
              u = i;
              md = d[i];
            }
        }

      if ( md == infty ) break;

      sv[u] = false;
      
      for ( auto i = 0; i < n; ++i )
        {
          if ( sv[i] && adj[u][i] >= 0 )
            {
              if ( d[u] + adj[u][i] < d[i] )
                {
                  d[i] = d[u] + adj[u][i];
                  
                }
            }
          
        }
    }

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

int main()
{
  SSSPath s;

  s.solve();

  return 0;
}