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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;
const int maxn=100+10;
const int maxv=10000+10;
const int INF=1<<21;
int n;
int E;
typedef struct
{
    int from,to,cost;
}Edge;

Edge e[maxv];
int d[maxn];
void bellman_ford(int s)
{
    fill(d,d+n,INF);
    d[s]=0;
    while(true)
    {
        bool bUpdate=false;
        for(int i=0;i<E;i++)
        {
            Edge es=e[i];
            if(d[es.from]!=INF&&d[es.to]>d[es.from]+es.cost)
            {
                d[es.to]=d[es.from]+es.cost;
                bUpdate=true;

            }
        }
        if(!bUpdate) break;

    }
    for(int i=0;i<n;i++)
    printf("%d %d\n",i,d[i]);
}
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d",&n);
    int id,c;
    E=0;
    for(int i=0; i<n; i++)
    {
        scanf("%d%d",&id,&c);
        while(c--)
        {
            scanf("%d%d",&e[E].to,&e[E].cost);
            e[E].from=id;
            E++;
        }
    }
    bellman_ford(0);

    return 0;
}

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

int min(int i,int j){
 return i>j?j:i;
}

int main(void){
 int n,u,k,c,v;
 vector<int> d;
 vector< vector<int> > edge;
 cin>>n;
 edge.resize(n);
 for(int i=0;i<n;i++){
 edge[i].resize(n);
}
 d.resize(n);
 d[0]=0;
 for(int i=1;i<n;i++){
  d[i]=100000000;
}
 for(int i=0;i<n;i++){
  for(int j=0;j<n;j++){
   edge[i][j]=1000000000;
  }
}
for(int i=0;i<n;i++){
 edge[i][i]=0;
}
for(int i=0;i<n;i++){
 cin>>u>>k;
 for(int j=0;j<k;j++){
  cin>>v>>c;
  edge[u][v]=c;
 }
}
for(int i=0;i<n;i++){
 for(int j=0;j<n;j++){
  for(int k=0;k<i;k++){
  d[j]=min(d[j],d[k]+edge[k][j]);}
 }
}

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

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
#define rep(i, n) for (int i = 0; i < n; i++)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

const int MAX = 100;
int cost[MAX][MAX];
int n;

void dijkstra() {
    int d[n];
    bool seen[n] = {};
    rep (i, n) { d[i] = inf; }
    d[0] = 0;
    while (1) {
        int minc = inf, now;
        rep (i, n) {
            if (minc > d[i] && !seen[i]) {
                minc = d[i];
                now = i;
            }
        }
        seen[now] = 1;
        if (minc == inf) break;
        rep (i, n) {
            if (cost[now][i] != inf && !seen[i]) {
                if (d[i] > cost[now][i] + d[now]) {
                    d[i] = cost[now][i] + d[now];
                }
            }
        }
    }
    rep (i, n) { cout << i << " " << d[i] << "\n"; }
    return;
}

int main() {
    cin >> n;
    rep (i, n) rep (j, n) cost[i][j] = inf;
    rep (i, n) {
        int now, k, next, c;
        cin >> now >> k;
        rep (i, k) {
            cin >> next >> c;
            cost[now][next] = c;
        }
    }
    dijkstra();
}