Go: package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

const (
	INFTY = 1 << 21
	NIL   = -1
)

const (
	WHITE = iota
	GRAY
	BLACK
)

type Graph [][]int

func (g *Graph) dikstra(n int) string {
	var (
		u, minv = 0, 0
	)

	d := make([]int, n)
	color := make([]int, n)

	for i := 0; i < n; i++ {
		d[i] = INFTY
		color[i] = WHITE
	}
	d[0] = 0
	color[0] = GRAY

	for {
		minv = INFTY
		u = -1
		for 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 v := 0; v < n; v++ {
			if color[v] != BLACK && (*g)[u][v] != INFTY {
				if d[v] > d[u]+(*g)[u][v] {
					d[v] = d[u] + (*g)[u][v]
					color[v] = GRAY
				}
			}
		}
	}

	var out bytes.Buffer
	for i := 0; i < n; i++ {
		out.WriteString(fmt.Sprintf("%d ", i))
		if d[i] == INFTY {
			out.WriteString(fmt.Sprintf("%d\n", -1))
			continue
		}
		out.WriteString(fmt.Sprintf("%d\n", d[i]))
	}

	return strings.TrimRight(out.String(), "\n")
}

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	g := make(Graph, n)
	for i := 0; i < n; i++ {
		g[i] = make([]int, n)
		for j := 0; j < n; j++ {
			g[i][j] = INFTY
		}
	}

	for i := 0; i < n; i++ {
		sc.Scan()
		u, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())

		for j := 0; j < k; j++ {
			sc.Scan()
			v, _ := strconv.Atoi(sc.Text())
			sc.Scan()
			c, _ := strconv.Atoi(sc.Text())

			g[u][v] = c
		}
	}

	return g.dikstra(n)
}

func main() {
	fmt.Println(answer(os.Stdin))
}

C++: #pragma once
#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wsign-compare"
#pragma GCC diagnostic ignored "-Wconversion"

using namespace std;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define RFOR(i, a, b) for (ll i = (b)-1; i >= (a); i--)
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep1(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define pii pair<int, int>

namespace is_stl_container_impl
{
template <typename T>
struct is_stl_container : false_type {
};
template <typename T, size_t N>
struct is_stl_container<array<T, N>> : true_type {
};
template <typename... Args>
struct is_stl_container<vector<Args...>> : true_type {
};
template <typename... Args>
struct is_stl_container<deque<Args...>> : true_type {
};
template <typename... Args>
struct is_stl_container<list<Args...>> : true_type {
};
template <typename... Args>
struct is_stl_container<forward_list<Args...>> : true_type {
};
template <typename... Args>
struct is_stl_container<set<Args...>> : true_type {
};
template <typename... Args>
struct is_stl_container<multiset<Args...>> : true_type {
};
template <typename... Args>
struct is_stl_container<map<Args...>> : true_type {
};
template <typename... Args>
struct is_stl_container<multimap<Args...>> : true_type {
};
template <typename... Args>
struct is_stl_container<unordered_set<Args...>> : true_type {
};
template <typename... Args>
struct is_stl_container<unordered_multiset<Args...>> : true_type {
};
template <typename... Args>
struct is_stl_container<unordered_map<Args...>> : true_type {
};
template <typename... Args>
struct is_stl_container<unordered_multimap<Args...>> : true_type {
};
template <typename... Args>
struct is_stl_container<stack<Args...>> : true_type {
};
template <typename... Args>
struct is_stl_container<queue<Args...>> : true_type {
};
template <typename... Args>
struct is_stl_container<priority_queue<Args...>> : true_type {
};
}  // namespace is_stl_container_impl

//type trait to utilize the implementation type traits as well as decay the type
template <typename T>
struct is_stl_container {
    static constexpr bool const value = is_stl_container_impl::is_stl_container<decay_t<T>>::value;
};

template <typename T>
typename enable_if<is_stl_container<T>::value, ostream&>::type operator<<(ostream& os, const T& container)
{
    os << "[";
    for (const auto& p : container) {
        os << p << ",";
    }
    os << "]";
    return os;
}

template <typename S, typename T>
ostream& operator<<(ostream& os, const pair<S, T>& p)
{
    os << "(" << p.first << "," << p.second
       << ")";
    return os;
}

using ll = long long;
constexpr ll MOD = 1000000007;

template <typename T>
constexpr T INF = numeric_limits<T>::max() / 100;

struct DGraph {
    using T = ll;
    DGraph(const int v) : V{v}
    {
        edge.resize(v);
        rev_edge.resize(v);
    }
    struct Edge {
        Edge(const int from, const int to, const T cost) : from{from}, to{to}, cost{cost} {}
        const int from;
        const int to;
        const T cost;
        bool operator<(const Edge& e) const
        {
            return cost != e.cost ? cost < e.cost : to < e.to;
        }
    };
    void addEdge(const int from, const int to, const T cost)
    {
        edge[from].push_back(Edge{from, to, cost});
        rev_edge[to].push_back(Edge(to, from, cost));
    }
    vector<vector<Edge>> edge;
    vector<vector<Edge>> rev_edge;
    const int V;
};

int main()
{
    int V, E, r;
    cin >> V >> E >> r;
    DGraph g{V};
    for (int i = 0; i < E; i++) {
        int s, t;
        ll c;
        cin >> s >> t >> c;
        g.addEdge(s, t, c);
    }
    vector<long long> d(V);
    Dijkstra(g, r, d);
    for (int i = 0; i < V; i++) {
        if (d[i] != INF<ll>) {
            cout << d[i] << endl;
        } else {
            cout << "INF" << endl;
        }
    }
    return 0;
}

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

using namespace std; 

int main(void) {
	int u,noe,nov;
	cin >> nov;
	vector< vector< pair<int,int> > > el(nov);
	for (int i = 0; i < nov; ++i) {
		cin >> u >> noe;
		el[u] = vector< pair<int,int> >(noe);
		for (int j = 0; j < noe; ++j) {
			cin >> el[u][j].first;
			cin >> el[u][j].second;
		}
	}

	vector<int> res(nov,(1 << 28));
	res[0] = 0;
	pair<int,int> now,next;
	priority_queue< pair<int,int> > q;
	q.push({0,0});
	while (!q.empty()) {
		now = q.top();
		q.pop();
		for (int i = 0; i < el[now.second].size(); ++i) {
			next = el[now.second][i];
			if (res[next.first] > now.first+next.second) {
				res[next.first] = now.first+next.second;
				q.push({res[next.first],next.first});
			}
		}
	}

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

	return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>

using namespace std;

int main() {

	int INF = 10000000;

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

	vector<pair<int, int>> G[n];
	for (int i = 0; i < n; ++i) {
		int from;
		scanf("%d", &from);

		int v;
		scanf("%d", &v);

		for (int j = 0; j < v; ++j) {
			int to;
			int w;
			scanf("%d %d", &to, &w);
			G[from].push_back(make_pair(to, w));
		}
	}

	int C[n];
	for (int i = 0; i < n; ++i)
		C[i] = INF;

	int color[n];
	int WHITE = 0;
	int BLACK = 1;
	for (int i = 0; i < n; ++i)
		color[i] = WHITE;

	priority_queue<pair<int, int>> PQ;
	PQ.push(make_pair(0, 0));
	C[0] = 0;
	while (!PQ.empty()) {
		int u = PQ.top().second;
		PQ.pop();
		color[u] = BLACK;
		for (int i = 0; i < (int) G[u].size(); ++i) {
			auto c = G[u][i];
			if (color[c.first] != BLACK && c.second + C[u] < C[c.first]) {
				C[c.first] = c.second + C[u];
				PQ.push(make_pair(C[c.first] * -1, c.first));
			}
		}
	}

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

	return 0;
}