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

int M[101][101];
int d[101];
int n;
vector<int> q;

int check(int point){
    if(find(q.begin(), q.end(), point) != q.end()){
        //printf("%d in q\n",point);
        return 1;
    }
    else{
        //printf("%d not in q\n",point);
        return 0;
    }
}

void dijk(int point){
    q.push_back(point);
    int node, mini = INT_MAX;

    while(q.size()!=n){
        mini = INT_MAX;
        for(int i=1;i<n;++i){
            if(mini>d[i] && check(i)==0){
                node = i;
                mini = d[i];
            }
        }
        q.push_back(node);
        //printf("push node %d\n",node);
        for(int i=0;i<n;++i){
            if(d[node]+M[node][i]<d[i]){
                d[i] = d[node]+M[node][i];
            }
        }
    }
}

int main(){
    int id, pair_n, source, dis;
    int value;
    //FILE *fp=fopen("In3.txt","r");
    scanf("%d",&n);
    for(int i=0;i<n;++i){
        for(int j=0;j<n;++j){
            M[i][j] = INT_MAX;
        }
    }
    for(int i=0;i<n;++i){
        scanf("%d %d",&id, &pair_n);
        //cin >> id >> pair_n;
        for(int j=0;j<pair_n;++j){
            scanf("%d %d",&source, &dis);
            //cin >> source >> dis;
            M[id][source] = dis;
        }
    }
    d[0] = 0;
    for(int i=1;i<n;++i){
        d[i] = M[0][i];
    }
    dijk(0);
    for(int i=0;i<n;++i){
        printf("%d %d\n",i,d[i]);
    }

    return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

class Graph
{
public:
    enum
    {
        WHITE = 0,
        GRAY = 1,
        BLACK = 2,
    };

    Graph() {}
    Graph(int n)
    : color(n, WHITE), M(n, vs32(n, INFTY)), d(n, INFTY), p(n, -1)
    {}
    ~Graph() {}

    void prim(int s)
    {
        d[s] = 0;
        
        while (true)
        {
            int minv = INFTY;
            int u = -1;
            rep (i, color.size())
            {
                if (color[i] != BLACK && minv > d[i])
                {
                    minv = d[i];
                    u = i;
                }
            }

            if (u < 0) break;
            d[u] = minv;
            color[u] = BLACK;

            rep (v, color.size())
            {
                if (color[v] != BLACK && d[v] > d[u] + M[u][v])
                {
                    d[v] = d[u] + M[u][v];
                    p[v] = u;
                    color[v] = GRAY;
                }
            }
        }
    }

    static const int INFTY = 1e9;
    vs32 color;
    vector< vs32 > M;
    vs32 d;
    vs32 p;
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    Graph g(n);

    int u, v;
    int w;
    int c;
    rep (i, n)
    {
        cin >> u >> c;
        rep (j, c)
        {
            cin >> v >> w;
            g.M[u][v] = w;
        }
    }

    g.prim(0);
    rep (i, n)
    {
        cout << i << " " << g.d[i] << "\n";
    }
    return 0;
}

C++: #include<stdio.h>
#include<stdlib.h>

#define rep( i ,end ) for( int i = 0 ; i < end ; ++i )
#define Nmax 100
#define INF ( INT_MAX / 10 )

int Node[ Nmax ][ Nmax ] ;

int min( int a ,int b )
{
	return a > b ? b : a ;
}

void Init( int NODE[ Nmax ][ Nmax ] ,int N )
{
	rep( i ,N )
	{
		rep( j ,N )
		{
			NODE[ i ][ j ] = ( i == j ) ? 0 : INF ;
		}
	}
}



int main( void )
{
	int N ,V ,K ;
	int v ,cost ;
	scanf( "%d" ,&N ) ;

	Init( Node ,N ) ;

	rep( i ,N )
	{
		scanf( "%d %d" ,&V ,&K ) ;

		rep( j ,K )
		{
			scanf( "%d %d" ,&v ,&cost ) ;

			Node[ V ][ v ] = cost ;
		}
	}

	rep( u ,N )
	{
		rep( i ,N )
		{
			rep( j ,N )
			{
				Node[ i ][ j ] = min( Node[ i ][ j ] ,Node[ i ][ u ] + Node[ u ][ j ] ) ;
			}
		}
	}

	rep( u ,N )
	{
		printf( "%d %d\n" ,u ,Node[ 0 ][ u ] ) ;
	}

	return 0 ;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>
#include <random>
#include <list>
#include <numeric>



#define rep(i,p,q) for(i = p;i < q;i++)
#define ll long long

using namespace std;

int v, e;



int main(void) {
	cin >> v;

	int i;
	ll d[100][100];
	int j;
	rep(i, 0, 100) {
		rep(j, 0, 100) {
			d[i][j] = i == j ? 0 : 1e11;
		}
	}
	rep(i, 0, v) {
		int u,k;
		cin >> u >> k;
		int i2;
		rep(i2, 0, k) {
			int t, c;
			cin >> t >> c;
			d[i][t] = c;
		}
		
		
	}

	int k;
	bool negative = false;
	rep(i, 0, v) {
		rep(j, 0, v) {
			rep(k, 0, v) {
				if (d[j][i] != 1e11 && d[i][k] != 1e11) {
					d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
				}

			}
		}
	}

	rep(i, 0, v) {
		cout << i << " " << d[0][i] << endl;
	}



}