Go: package main

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

const (
	white int = iota
	gray
	black
)

type node struct {
	id     int
	parent int
	edge   []int
	weight []int
	color  int
}

type graph struct {
	nodes    []node
	distance []int
}

var infty = 1 << 32
var null = -1

func constructgraph() *graph {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)

	g := &graph{make([]node, n), make([]int, n)}

	for i := 0; i < n; i++ {
		id := nextInt(sc)
		edges := nextInt(sc)
		n := node{}
		n.id = id
		n.edge = make([]int, edges)
		n.weight = make([]int, edges)
		n.color = white
		for j := 0; j < edges; j++ {
			to := nextInt(sc)
			w := nextInt(sc)
			n.edge[j] = to
			n.weight[j] = w
		}
		g.nodes[id] = n
	}
	return g
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func (g *graph) preparedijkstra(s int) {
	for i := 0; i < len(g.nodes); i++ {
		g.nodes[i].color = white
		g.nodes[i].parent = null
		g.distance[i] = infty
	}
	g.distance[s] = 0
}

func (g *graph) dijkstra(s int) []int {
	g.preparedijkstra(s)

	for {
		var u int
		mincost := infty
		for i, d := range g.distance {
			if g.nodes[i].color != black && mincost > d {
				mincost = d
				u = i
			}
		}

		if mincost == infty {
			break
		}

		g.nodes[u].color = black

		for i, e := range g.nodes[u].edge {
			if g.nodes[e].color != black {
				if g.distance[e] > g.distance[u]+g.nodes[u].weight[i] {
					g.distance[e] = g.distance[u] + g.nodes[u].weight[i]
					g.nodes[e].parent = u
					g.nodes[e].color = gray
				}
			}
		}
	}
	return g.distance
}

func printShortestPath(d []int) {
	for i, v := range d {
		fmt.Printf("%d %d\n", i, v)
	}
}

func main() {
	g := constructgraph()
	d := g.dijkstra(0)
	printShortestPath(d)
}

C++: #include<bits/stdc++.h>
using namespace std;

static const int N = 100;
static const int inf = (1 << 30);
static const int white = 0;
static const int gray = 1;
static const int black = 2;

int n, M[N][N];

void dijkstra(int s) {
	int color[N], d[N];
	for (int i = 0; i < n; i++) {
		color[i] = white;
		d[i] = inf;
		//p[n] = inf;
	}
	d[s] = 0;
	color[s] = gray;
	int u = -1;
	while (true) {
		int mincost = inf;
		for (int i = 0; i < n; i++) {
			if (color[i] != black && d[i] < mincost) {
				mincost = d[i];
				u = i;
			}
		}
		if (mincost == inf) {
			break;
		}
		color[u] = black;
		for (int v = 0; v < n; v++) {
			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;
					//p[v] = u;
				}
			}
		}
	}
	for (int i = 0; i < n; i++) {
		cout << i << " " << (d[i] == inf ? -1 : d[i]) << '\n';
	}
	//return  0;
}

int main() {
	int u, k, v, c;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			M[i][j] = inf;
		}
	}
	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			cin >> v >> c;
			M[u][v] = c;
		}
	}
/*	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (M[i][j] == inf) {
				cout << -1  << " ";
			} else {
				cout << M[i][j] << " ";
			}
		}
		cout << '\n';
}
*/
	dijkstra(0);
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <tuple>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <random>
#include <cstdlib>
#define INT_MAX 2147483647
#define INT_MIN -2147483646
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

static const int N = 105;

struct vertex {
	int id;
	int p;
	int d;
	bool operator<(const vertex & another) const {
		return (d != another.d ? d>another.d : id>another.id);
	}
};

struct edge {
	int end;
	int w;
};

int main() {
	int n;
	cin >> n;
	vector<vector<edge>> E(N);
	Loop(i, n) {
		int u, k;
		cin >> u >> k;
		Loop(i, k) {
			int v, c;
			cin >> v >> c;
			E[u].push_back({ v,c });
		}
	}
	//
	priority_queue<vertex> pq;
	vi color(N, 0), dist(N, 0);
	pq.push({ 0,-1,0 });
	while (pq.size() > 0) {
		vertex v = pq.top();
		pq.pop();
		if (color[v.id] == 1) continue;
		dist[v.id] = v.d;
		color[v.id] = 1;
		Loop(j, E[v.id].size()) {
			pq.push({ E[v.id][j].end, v.id, dist[v.id] + E[v.id][j].w });
		}
	}
	Loop(i, n) {
		cout << i << " " << dist[i] << endl;
	}
	return 0;
}

C++: # include <iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

void init() {
    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 >> v >> c;
            M[u][v] = c;
        }
    }
}

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

void solve() {
    init();
    dijkstra();
}

int main() {
    // freopen("infile", "r", stdin);
    // freopen("outfile", "w", stdout);
    solve();
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define INF 100000000
#define WH 0
#define GR 1
#define BK 2

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

    int color[100] = {};

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

    int p[100];
    for (int i = 0; i < n; i++) {
        p[i] = -1;
    }

    while (true) {
        d[0] = 0;

        int min_cost = INF;
        int u;
        for (int i = 0; i < n; i++) {
            if (color[i] != BK && d[i] < min_cost) {
                min_cost = d[i];
                u = i;
            }
        }

        if (min_cost == INF) {
            break;
        }

        color[u] = BK;

        for (int v = 0; v < n; v++) {
            if (color[v] != BK && M[u][v] < INF) {
                if (d[u] + M[u][v] < d[v]) {
                    d[v] = d[u] + M[u][v];
                    p[v] = u;
                    color[v] = GR;
                }
            }
        }
    }

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


    // for (int i = 0; i < n; i++) {
    //     for (int j = 0; j < n; j++) {
    //         cout << " " << M[i][j];
    //     }
    //     cout << endl;
    // }

    return 0;
}