Go: package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)

	g := makeGraph(n)
	for i := 0; i < n; i++ {
		u := getNextInt(scanner)
		k := getNextInt(scanner)
		for ii := 0; ii < k; ii++ {
			v := getNextInt(scanner)
			c := getNextInt(scanner)
			g[u][v] = c
		}
	}

	ans := make([]int, n)
	im := make(IntMap, 1)
	im.increment(0)
	for len(im) < n {
		min := 1 << 30
		x := -1
		for u := range im {
			for v := 0; v < n; v++ {
				if im.get(v) != 0 {
					continue
				}
				if min > ans[u]+g[u][v] {
					min = ans[u] + g[u][v]
					x = v
				}
			}
		}
		im.increment(x)
		ans[x] = min
	}

	for i := 0; i < n; i++ {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d", i, ans[i]))
	}
	writer.Flush()
}

func makeGraph(n int) [][]int {
	g := make([][]int, n)
	for i := 0; i < n; i++ {
		g[i] = make([]int, n)
		for ii := 0; ii < n; ii++ {
			g[i][ii] = 1 << 30
		}
	}

	return g
}

// IntMap ...
type IntMap map[int]int

func (m IntMap) get(key int) int {
	if _, ok := m[key]; ok {
		return m[key]
	}
	return 0
}
func (m IntMap) increment(key int) {
	if _, ok := m[key]; ok == false {
		m[key] = 0
	}
	m[key]++
}

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

using namespace std;
using ll = long long;

template <class T>
struct Edge {
    int to;
    T cost;
    Edge(int to, T cost) : to(to), cost(cost){};
};

template <class T = int>
class Graph {
public:
    explicit Graph(int N = 0) : size(N) { path.resize(size); }
    void span(int u, int v, T cost = 1) { path[u].push_back(Edge<T>(v, cost)); }
    vector<Edge<T>> operator[](int v) const { return path[v]; }

    int size;
    vector<vector<Edge<T>>> path;
};

const ll INF = 1LL << 50;

template <class T>
vector<T> dijkstra(const Graph<T>& graph, int s) {
    vector<T> dist(graph.size, INF);
    dist[s] = 0;

    priority_queue<pair<int, T>, vector<pair<int, T>>, greater<pair<int, T>>> que;
    que.push(make_pair(0, s));

    while (!que.empty()) {
        int v;
        T d;
        tie(d, v) = que.top();
        que.pop();
        if (d > dist[v]) continue;

        for (const auto& e : graph[v]) {
            if (dist[e.to] <= dist[v] + e.cost) continue;
            dist[e.to] = dist[v] + e.cost;
            que.push(make_pair(dist[e.to], e.to));
        }
    }
    return dist;
}

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

    Graph<ll> graph(N);
    for (int i = 0; i < N; ++i) {
        int v, k;
        cin >> v >> k;
        for (int j = 0; j < k; ++j) {
            int sv;
            ll c;
            cin >> sv >> c;
            graph.span(v, sv, c);
        }
    }

    auto dist = dijkstra<ll>(graph, 0);
    for (int v = 0; v < N; ++v) cout << v << " " << dist[v] << endl;
    return 0;
}

C++: #include <stdio.h>
#include <stdint.h>
#include <iostream>
#include <fstream>
#include <cassert>
#include <climits>

#include <queue>
using namespace std;

#define DEBUG (0)

#if DEBUG
#define DPRINTF(...) do { \
    printf("D(L%d) %s: ", __LINE__, __func__); \
    printf(__VA_ARGS__); \
  } while (false)
#else
#define DPRINTF(...)
#endif // DEBUG


const int kMaxVertex = 100;
int g_num_of_vertex;
int g_min_weight[kMaxVertex];


enum State {
    kUnvisited = 0,
    kVisited,
};


struct Edge {
    Edge(int num_vertex)
        : num_vertex_(num_vertex)
    {
        const int size_of_ptr_ = num_vertex_ * num_vertex_;
        weight_ = unique_ptr<int>(new int[size_of_ptr_]);

        for (int i = 0; i < num_vertex_; i++)
            for (int j = 0; j < num_vertex_; j++)
                setWeight(i, j, kInvalidWeight);

        for (int i = 0; i < num_vertex_; i++)
            setWeight(i, i, 0);
    }

    const int kInvalidWeight = INT_MAX;

    bool isConnected(int v0, int v1) const;
    vector<int> getConnectedVertices(int v) const;
    int getWeight(int v0, int v1) const;
    void setWeight(int v0, int v1, int w);

    void printWeight() const;

    int num_vertex_;
    int size_of_ptr_;
    unique_ptr<int> weight_;
};

bool Edge::isConnected(int v0, int v1) const
{
    if (v0 == v1)
        return false;

    if (getWeight(v0, v1) == kInvalidWeight)
        return false;

    return true;
}

vector<int> Edge::getConnectedVertices(int v) const
{
    vector<int> vertices;

    for (int i = 0; i < num_vertex_; i++)
        if (isConnected(v, i))
            vertices.push_back(i);

    return vertices;
}

void Edge::setWeight(int v0, int v1, int w)
{
    assert(0 <= v0 && v0 < num_vertex_);
    assert(0 <= v1 && v1 < num_vertex_);

    int *p = weight_.get() + (v0 * num_vertex_) + v1;
    *p = w;
}

int Edge::getWeight(int v0, int v1) const
{
    int *p = weight_.get() + (v0 * num_vertex_) + v1;
    return *p;
}

void Edge::printWeight() const
{
    DPRINTF("\n");
    for (int i = 0; i < num_vertex_; i++)
    {
        printf("    [%d]", i);
        for (int j = 0; j < num_vertex_; j++)
        {
            printf(" %d", getWeight(i, j));
        }
        cout << endl;
    }
}


struct VtxAndWeight {
    VtxAndWeight(int vtx, int weight)
        : vtx_(vtx)
        , weight_(weight)
    {}

    int vtx_;
    int weight_;
};


void calcShortestPath(int start, const Edge &edge)
{
    DPRINTF("start %d\n", start);
    assert(0 <= start && start < g_num_of_vertex);

    int current = start;
    int weight = 0;

    queue<VtxAndWeight> que;
    que.push(VtxAndWeight(current, weight));

    while (!que.empty())
    {
        VtxAndWeight vw = que.front();
        que.pop();

        int vtx = vw.vtx_;
        int weight = vw.weight_;

        DPRINTF("vtx %d  weight %d\n", vtx, weight);

        if (weight > g_min_weight[vtx])
        {
            continue;
        }
        g_min_weight[vtx] = weight;

        vector<int> connectedVertices = edge.getConnectedVertices(vtx);

        // update weight
        // push to queue as the next vertex to be visited
        for (int next_vtx : connectedVertices)
        {
            int next_weight = weight + edge.getWeight(vtx, next_vtx);
DPRINTF("next_vtx %d  next_weight %d\n", next_vtx, next_weight);
            que.push(VtxAndWeight(next_vtx, next_weight));
        }

    }

}


int main()
{
    cin >> g_num_of_vertex;
    cin.ignore();

    // init
    for (int i = 0; i < g_num_of_vertex; i++)
    {
        g_min_weight[i] = INT_MAX;
    }

    Edge edge(g_num_of_vertex);

    // input
    for (int i = 0; i < g_num_of_vertex; i++)
    {
        int start, degree;
        cin >> start >> degree;

        for (int j = 0; j < degree; j++)
        {
            int dst, weight;
            cin >> dst >> weight;

            edge.setWeight(start, dst, weight);
        }

        cin.ignore();
    }

#if DEBUG
    edge.printWeight();
#endif

    // process
    const int start = 0;
    calcShortestPath(start, edge);

    // output
    for (int i = 0; i < g_num_of_vertex; i++)
        printf("%d %d\n", i, g_min_weight[i]);

    return 0;
}