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 <bits/stdc++.h>
using namespace std;

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
// #define SORT(v, n) stable_sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const int MAX   = 100;
const int INF   = (1 << 21);
const int white = 0;
const int gray  = 1;
const int black = 2;

int n, m[MAX][MAX];

int dijkstra() {
    int minV;
    int d[MAX], color[MAX];
    rep(i, n) {
        d[i]     = INF;
        color[i] = white;
    }

    d[0]     = 0;
    color[0] = gray;
    while (1) {
        minV  = INF;
        int u = -1;
        rep(i, n) {
            if (minV > d[i] && color[i] != black) {
                u    = i;
                minV = d[i];
            }
        }
        if (u == -1) break;
        color[u] = black;
        rep(v, n) {
            if (color[v] != black && m[u][v] != INF) {
                if (d[v] > d[u] + m[u][v]) {
                    d[v]     = d[u] + m[u][v];
                    color[v] = gray;
                }
            }
        }
    }
    rep(i, n) { cout << i << " " << (d[i] == INF ? -1 : d[i]) << endl; }
}

// 単一始点最短経路
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // cout << fixed << setprecision(5);

    cin >> n;
    rep(i, n) {
        rep(j, n) { m[i][j] = INF; }
    }

    int k, c, u, v;
    rep(i, n) {
        cin >> u >> k;
        rep(j, k) {
            cin >> v >> c;
            m[u][v] = c;
        }
    }

    dijkstra();

    return 0;
}

C++: #include <stdio.h>
#define MAX 100
static const int INFTY = (1<<21);
int n,A[MAX][MAX];

void dikusutora();

int main(){
  int i,j,m,k,d,h;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      A[i][j]=INFTY;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d",&m);
    scanf("%d",&k);
    for(j=0;j<k;j++){
      scanf("%d",&d);
      scanf("%d",&h);
      A[m][d]=h;
    }
  }
  dikusutora();
  return 0;
}
void dikusutora(){
  int min,i,e,v;
  int g[MAX],a[MAX];

  for(i=0;i<n;i++){
    g[i]=INFTY;
    a[i]=0;
  }
  g[0]=0;
  a[0]=1;
  
  while(1){
    min=INFTY;
    e=-1;
    for(i=0;i<n;i++){
      if(min>g[i]&&a[i]!=2){
	e=i;
	min=g[i];
      }
    }
    if(e==-1)
      break;
    a[e]=2;
    for(v=0;v<n;v++){
      if(a[v]!=2&&A[e][v]!=INFTY){
	if(g[v]>g[e]+A[e][v]){
	  g[v]=g[e]+A[e][v];
	  a[v]=1;
	}
      }
    }
  }
  for(i=0;i<n;i++){
    printf("%d",i);
    printf(" ");
    if(g[i]==INFTY)
      printf("-1");
    else printf("%d",g[i]);
    printf("\n");
  }
}

C++: #include "bits/stdc++.h"
using namespace std;
int main()
{
    int n, inf = 1000000000;
    scanf("%d", &n);
    vector<vector<int>> a(n, vector<int>(n, inf));
    for (int i = 0, u, k; i < n; i++)
    {
        scanf("%d %d", &u, &k);
        for (int j = 0, v, c; j < k; j++)
        {
            scanf("%d %d", &v, &c);
            a[u][v] = c;
        }
    }
    vector<int> cost(n, inf);
    vector<bool> vis(n, false);
    cost[0] = 0;
    for (int mi = inf, tip = 0; ; mi = inf)
    {
        for (int i = 0; i < n; i++)
        {
            if (!vis[i] && cost[i] < mi)
            {
                mi = cost[i];
                tip = i;
            }
        }
        
        if (mi == inf)
        {
            break;
        }
        vis[tip] = true;
        for (int i = 0; i < n; i++)
        {
            
            if (!vis[i] && a[tip][i] != inf)
            {
                
                if (cost[tip] + a[tip][i] < cost[i])
                {
                    cost[i] = cost[tip] + a[tip][i];
                }
            }
        }
    }
    
    for (int i = 0; i < n; i++)
    {
        printf("%d %d\n", i, cost[i]);
    }
}