Go: package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

const NIL = -1

type Node struct {
	id     int
	weight int
}

func init() {
	sc.Split(bufio.ScanWords)
}

type NodeHeap []Node

func (h NodeHeap) Len() int           { return len(h) }
func (h NodeHeap) Less(i, j int) bool { return h[i].weight < h[j].weight }
func (h NodeHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *NodeHeap) Push(x interface{}) {
	*h = append(*h, x.(Node))
}

func (h *NodeHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()

	list := make([][]int, n)
	weight := make([]int, n)
	for i := range list {
		list[i] = make([]int, n)
		weight[i] = NIL
		for j := range list[i] {
			list[i][j] = NIL
		}
	}

	for i := 0; i < n; i++ {
		u := scanInt()
		k := scanInt()
		for j := 0; j < k; j++ {
			v := scanInt()
			w := scanInt()
			list[u][v] = w
		}
	}

	start := Node{id: 0, weight: 0}
	h := &NodeHeap{start}
	heap.Init(h)

	for h.Len() > 0 {
		node := heap.Pop(h).(Node)
		if weight[node.id] != NIL {
			continue
		}
		weight[node.id] = node.weight

		for i, w := range list[node.id] {
			if w == NIL {
				continue
			}
			heap.Push(h, Node{id: i, weight: w + node.weight})
		}
	}

	w := bufio.NewWriter(os.Stdout)
	for i := 0; i < n; i++ {
		fmt.Fprint(w, i)
		fmt.Fprint(w, " ")
		fmt.Fprint(w, weight[i])
		fmt.Fprintln(w)
	}
	w.Flush()
}

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

#define NUM 100
#define NIL -1
#define INF 1000000000
#define WHITE 0
#define BLACK 1
int node_num;
vector<tuple<int, int>> G[NUM];
int V[NUM];
int color[NUM];

void init(void){
    scanf("%d", &node_num);

    for(int i = 0; i < node_num; i++){
        int u, k;
        scanf("%d", &u);
        scanf("%d", &k);

        for(int j = 0; j < k; j++){
            int v_, c;
            scanf("%d", &v_);
            scanf("%d", &c);
            G[u].push_back(make_tuple(v_, c));
        }
    }

    for(int i = 0; i < node_num; i++){
        color[i] = WHITE;
        V[i] = INF;
    }
}

void updateAround(int n){
    color[n] = BLACK;
    for(int i = 0; i < G[n].size(); i++){
        V[get<0>(G[n][i])] = min(V[get<0>(G[n][i])], V[n] + get<1>(G[n][i]));
    }

    int min_index = NIL;
    int min_value = INF;
    for(int i = 0; i < node_num; i++){
        if(color[i] == BLACK){
            continue;
        }
        if(V[i] < min_value){
            min_value = V[i];
            min_index = i;
        }
    }
    if(min_index != NIL){
        updateAround(min_index);
    }
}

int main(void){
    init();

    V[0] = 0;
    updateAround(0);

    for(int i = 0; i < node_num; i++){
        printf("%d %d\n", i, V[i]);
    }
}

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

const int INF = 0xfffffff;
const int MAX = 10000;

struct Edge {
	Edge() {};
	Edge(int v, int c) :v(v), c(c) {};
	bool operator < (const Edge& e)const {
		return c > e.c;
	}
	int v;
	int c;
};

int main() {
	int n;
	priority_queue<Edge> graph[MAX];
	vector<Edge> table;
	bool check[MAX] = { false };
	int ary[MAX] = { 0 };

	cin >> n;

	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			Edge e;
			cin >> e.v >> e.c;
			graph[u].push(e);
		}
	}

	Edge e(0, 0);
	table.push_back(e);
	check[0] = true;

	for (int i = 1; i < n; i++) {
		Edge minv(0, INF);
		int erase = 0;

		for (int j = 0; j < table.size(); j++) {
			int v = table[j].v;
			int c = table[j].c;	
			while (!graph[v].empty() && check[graph[v].top().v])graph[v].pop();
			if (graph[v].empty())continue;
			if (c + graph[v].top().c < minv.c) {
				minv.c = c + graph[v].top().c;
				minv.v = graph[v].top().v;
				erase = v;
			}
		}
		table.push_back(minv);
		check[minv.v] = true;
		graph[erase].pop();
	}
	
	for (int i = 0; i < n; i++) {
		ary[table[i].v] = table[i].c;
	}
	for (int i = 0; i < n; i++) {
		cout << i << " " << ary[i] << endl;
	}

	return 0;
}

C++: #include <cstdio>
#include <queue>
#include <utility>
using namespace std;
static const int INFTY = (1 << 10);
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>
#include <queue>

using namespace std;

const int INFTY = (1 << 30);

struct Node
{
    int node;
    int cost;
    Node(int n = 0, int c = INFTY) : node(n), cost(c) {}
};

bool operator<(const Node &n1, const Node &n2)
{
    return n1.cost < n2.cost;
}

class Dks
{
    vector<vector<int>> cost;
    vector<int> state, parent, dist;

public:
    Dks(int n = 0)
    {
        cost.resize(n);
        state.resize(n);
        parent.resize(n);
        dist.resize(n, INFTY);
    }

    void load_cost()
    {
        int node, n_v, v, c;
        for (int i = 0; i < cost.size(); i++)
        {
            cin >> node >> n_v;
            cost.at(node).resize(cost.size(), INFTY);
            for (int j = 0; j < n_v; j++)
            {
                cin >> v >> c;
                cost.at(node).at(v) = c;
            }
        }
    }

    void dks(int node)
    {
        int min_value;
        dist[node] = 0;
        while(true)
        {
            node = -1;
            min_value = INFTY;
            for(int i = 0;i<cost.size();i++){
                if(state[i] == 0 && dist[i] < min_value){
                    node = i;
                    min_value = dist[i];
                }
            }
            if(node == -1) break;
            state[node] = 1;

            for (int j = 0; j < cost.size(); j++)
            {
                if(cost[node][j] == INFTY) continue;
                if (state[j] == 0 && dist[j] > dist[node] + cost[node][j])
                {
                    dist[j] = dist[node] + cost[node][j];
                    parent[j] = node;
                }
            }
        }
    }

    void print(){
        for(int i=0;i<cost.size();i++){
            cout << i << " " << (dist[i] == INFTY ? -1 : dist[i]) << endl;
        }
    }
};

int main()
{
    int N;
    cin >> N;
    Dks dks(N);
    dks.load_cost();
    dks.dks(0);
    dks.print();
}