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 <iostream>
#include <vector>
#include <utility>
#include <queue>
// #include <string>
using namespace std;

vector<string> split(string s, string delimiter)
{
    int pos_start = 0, pos_end, delim_len = delimiter.length();
    string token;
    vector<string> res;

    while ((pos_end = s.find(delimiter, pos_start)) != string::npos)
    {
        token = s.substr(pos_start, pos_end - pos_start);
        pos_start = pos_end + delim_len;
        res.push_back(token);
    }

    res.push_back(s.substr(pos_start));
    return res;
}

vector<int> dijkstra(int n, vector<vector<int>> adj_matrix)
{
    vector<int> d(n, 1e9);
    vector<int> prev(n);
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> Q;

    d[0] = 0;
    for (int i = 0; i < n; i++)
    {
        Q.push(make_pair(d[i], i));
    }

    while (!Q.empty())
    {
        int u = Q.top().second;
        // int c = Q.top().first;
        Q.pop();

        for (int i = 0; i < n; i++)
        {
            if (adj_matrix[u][i] > 0)
            {
                int tmp = d[u] + adj_matrix[u][i];
                if (tmp < d[i])
                {
                    d[i] = tmp;
                    prev[i] = u;
                    Q.push(make_pair(d[i], i));
                }
            }
        }
    }

    return d;
}

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

    int n;
    cin >> n;
    cin.ignore();
    vector<vector<int>> adj_matrix;
    adj_matrix.resize(n);
    for (int i = 0; i < adj_matrix.size(); i++)
    {
        adj_matrix[i].resize(n);
    }

    for (int i = 0; i < n; i++)
    {
        string s;
        getline(cin, s);
        vector<string> tmp = split(s, " ");
        int u = stoi(tmp[0]);
        int k = stoi(tmp[1]);

        for (int j = 2; j < tmp.size(); j += 2)
        {
            int v = stoi(tmp[j]);
            adj_matrix[u][v] = stoi(tmp[j + 1]);
        }
    }

    vector<int> ans = dijkstra(n, adj_matrix);
    for (int i = 0; i < n; i++)
    {
        cout << i << " " << ans[i] << endl;
    }

    return 0;
}

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

int n;
vector<pair<int, int>> adj[100];
int *d;

void dijkstra() {
    priority_queue<pair<int, int>> PQ;
    int d[n], color[n];

    for (int i = 0; i < n; i++) {
        d[i] = INFTY;
        color[n] = WHITE;
    }
    d[0] = 0;
    PQ.push(make_pair(0, 0));

    while (!PQ.empty()) {
        pair<int, int> f = PQ.top();
        PQ.pop();

        int u = f.second;
        color[u] = BLACK;

        if (d[u] < f.first * (-1)) { continue; }

        for (int j = 0; j < adj[u].size(); j++) {
            int v = adj[u][j].first;
            if (color[v] == BLACK) { continue; }
            if (d[u] + adj[u][j].second < d[v]) {
                d[v] = d[u] + adj[u][j].second;
                // printf("d[%d] = %d\n", v, d[v]);
                PQ.push(make_pair(d[v] * (-1), v));
                color[v] = GRAY;
            }
        }
    }
    
    for (int i = 0; i < n; i++) {
        printf("%d %d\n", i, d[i]);
    }
}

int main() {
    scanf("%d", &n);

    // adj = new vector<pair<int, int>>[n];

    for (int i = 0; i < n; i++) {
        int u, k;
        scanf("%d %d", &u, &k);
        for (int j = 0; j < k; j++) {
            int v, c;
            scanf("%d %d", &v, &c);
            adj[u].push_back(make_pair(v, c));
        }
    }

    dijkstra();

    return 0;
}

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

int n;
const int INF = 1000000;
vector<vector<int> > v, c;
vector<int> w;

void trip(int id, int dp) {
	if (dp > n)
		return;

	for (int j = 0; j < (int)v[id].size(); j++) {
		if (w[v[id][j]] > w[id] + c[id][j]) {
			w[v[id][j]] = w[id] + c[id][j];
			trip(v[id][j], dp + 1);
		}
	}
}

int main()
{
	cin >> n;

	int u, k, v1, c1;
	v.resize(n);
	c.resize(n);
	w.assign(n, INF);

	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			cin >> v1 >> c1;
			v[u].push_back(v1);
			c[u].push_back(c1);
		}
	}

	w[0] = 0;
	trip(0, 1);

	for (int i = 0; i < n; i++)
		cout << i << " " << w[i] << endl;

	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <queue>
#include <vector>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

/*
 * dijkstra 法 O(Elog(V))
 * グラフ g において, 始点 start から各頂点への最短経路を返す
*/
struct Edge {
public:
  int to, cost;

  Edge() {}
  Edge(int to, int cost) : to(to), cost(cost) {}
};

std::vector<int> dijkstra(std::vector<std::vector<Edge> >& graph, int start) {
  std::vector<int> d(graph.size(), int(1e9));
  // (x, y) ... x : the minimum distance from start to y, y : now vertex 
  std::priority_queue<std::pair<int, int> > que;

  que.push({0, start});
  d[start] = 0;

  while(!que.empty()) {
    auto p = que.top();
    que.pop();

    for (auto e : graph[p.second]) {
      if (d[e.to] <= p.first + e.cost) continue;

      d[e.to] = p.first + e.cost;
      que.push({d[e.to], e.to});
    }
  }

  return d;
}


int main() {
  int n, u, k, v, c;
  std::vector<std::vector<Edge> > g;

  cin >> n;
  g.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> u >> k;
    for (int j = 0; j < k; ++j) {
      cin >> v >> c;
      g[u].push_back({v, c});
    }
  }

  auto d = dijkstra(g, 0);

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

  return 0;
}