Go: package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
type Node struct {
	cost int
	done bool
}

type Edge struct {
	to, cost int
}

const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	nodes := make([]Node, N)
	for i := 0; i < N; i++ {
		nodes[i].cost = INF
	}
	E := make([][]Edge, N)
	for i := 0; i < N; i++ {
		id, k := sc.nextInt(), sc.nextInt()
		for j := 0; j < k; j++ {
			to, cost := sc.nextInt(), sc.nextInt()
			E[id] = append(E[id], Edge{to, cost})
		}
	}
	nodes[0].cost = 0
	for {
		cur := 0
		minCost := INF
		for i := 0; i < N; i++ {
			n := nodes[i]
			if !n.done && n.cost < minCost {
				cur = i
				minCost = n.cost
			}
		}
		if minCost == INF {
			break
		}
		nodes[cur].done = true
		for i := 0; i < len(E[cur]); i++ {
			to, cost := E[cur][i].to, E[cur][i].cost+nodes[cur].cost
			if !nodes[to].done && cost < nodes[to].cost {
				nodes[to].cost = cost
			}
		}
	}

	for i := 0; i < N; i++ {
		fmt.Fprintln(wtr, i, nodes[i].cost)
	}
	wtr.Flush()
}

C++: #include<iostream>
using namespace std;
static const int MAX=100;
static const int INFTY=(1<<21);
static const int white=01;
static const int gray=1;
static const int black=2;

int n,M[MAX][MAX];
void dijkstra(){
    int minv;
    int d[MAX],color[MAX];

    for(int i=0;i<n;i++){
	d[i]=INFTY;
	color[i]=white;
    }
    d[0]=0;
    color[0]=gray;
    while(1){
	minv=INFTY;
	int u=-1;
	for(int i=0;i<n;i++){
	    if(minv>d[i]&&color[i]!=black){
		u=i;
		minv=d[i];
	    }
	}
	if(u==-1)break;

	color[u]=black;
	for(int v=0;v<n;v++){
	    if(color[v]!=black&&M[u][v]!=INFTY){
		if(d[v]>d[u]+M[u][v]){
		    d[v]=d[u]+M[u][v];
		    color[v]=gray;
		}
	    }
	}
    }
    for(int i=0;i<n;i++){
	cout<<i<<" "<<(d[i]==INFTY?-1:d[i])<<endl;
    }
}
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
	for(int j=0;j<n;j++){
	    M[i][j]=INFTY;
	}
    }

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

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();
}