Go: package main

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

const BIG_COST = 200000

const (
	ST_NOT_YET = iota
	ST_JOINED
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	nNodes := scanInt(sc)

	costs := make([][]int, nNodes)
	graph := make([][]int, nNodes)

	states := make([]int, nNodes)
	costSums := make([]int, nNodes)

	for i := 0; i < nNodes; i++ {
		costs[i] = make([]int, nNodes)
		costSums[i] = BIG_COST
	}

	for i := 0; i < nNodes; i++ {
		u := scanInt(sc)
		k := scanInt(sc)
		graph[u] = make([]int, k)
		for d := 0; d < k; d++ {
			v := scanInt(sc)
			graph[u][d] = v
			costs[u][v] = scanInt(sc)
		}
	}

	costSums[0] = 0
	for {
		minCost := BIG_COST
		var u int

		for i, cost := range costSums {
			if states[i] != ST_JOINED && cost < minCost {
				minCost = cost
				u = i
			}
		}

		if minCost == BIG_COST {
			break
		}

		states[u] = ST_JOINED

		for _, v := range graph[u] {
			cost := minCost + costs[u][v]
			if cost < costSums[v] {
				costSums[v] = cost
			}
		}
	}

	w := bufio.NewWriter(os.Stdout)
	for i, cost := range costSums {
		fmt.Fprintf(w, "%d %d\n", i, cost)
	}
	w.Flush()
}

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

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

using namespace std;
using graph = vector<vector<int>>;


int main() {
    int n;
    cin >> n;

    graph G(n, vector<int>(n, -1));
    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;
            G[u][v] = c;
        }
    }

    // Dijkstra's algorithm
    vector<int> d(n, -1);
    vector<bool> visited(n, false);

    d[0] = 0;
    visited[0] = true;
    while (1) {
        int u = -1;
        int v = -1;
        int minw = numeric_limits<int>::max();
        for (int i = 0; i < n; ++i) {
            if (!visited[i])
                continue;
            for (int j = 0; j < n; ++j) {
                if (visited[j] && G[i][j] < 0)
                    continue;
                int w = G[i][j] + d[i];
                if (w < minw) {
                    u = i;
                    v = j;
                    minw = w;
                }
            }
        }
        if (v < 0) {
            break;
        }
        d[v] = minw;
        visited[v] = true;
    }

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

    return 0;
}

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

void Dijkstra(const DGraph& g, const int s, vector<DGraph::T>& d)
{
    using T = DGraph::T;
    assert(s < g.V);
    assert(d.size() == g.V);
    using P = pair<T, int>;
    priority_queue<P, vector<P>, greater<P>> q;
    for (int i = 0; i < g.V; i++) {
        d[i] = INF<T>;
    }
    d[s] = 0;
    q.push(make_pair(0, s));
    while (not q.empty()) {
        const P& p = q.top();
        const T cost = p.first;
        const int v = p.second;
        q.pop();
        if (d[v] < cost) {
            continue;
        }
        for (const auto& e : g.edge[v]) {
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                q.push(make_pair(d[e.to], e.to));
            }
        }
    }
}

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