Go: package main

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

type Node struct {
	Id int
	Dis int
}

type PriorityQueue []*Node

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].Dis < pq[j].Dis
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *PriorityQueue) Push(x interface{}) {
	*pq = append(*pq, x.(*Node))
}

func (pq *PriorityQueue) Pop() interface{} {
	n := len(*pq)
	pop := (*pq)[n-1]
	*pq = (*pq)[0:n-1]
	return pop
}

func main() {
	var n int
	fmt.Scan(&n)

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

	g := make([][]int, n)
	c := make([][]int, n)
	pq := make(PriorityQueue, 0, n)
	d := make([]int, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		u, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())
		g[u] = make([]int, k)
		c[u] = make([]int, k)
		for j := 0; j < k; j++ {
			sc.Scan()
			g[u][j], _ = strconv.Atoi(sc.Text())
			sc.Scan()
			c[u][j], _ = strconv.Atoi(sc.Text())
		}

		if u == 0 {
			d[u] = 0
		} else {
			d[u] = 1 << 30
		}
		pq.Push(&Node{u, d[u]})
	}
	heap.Init(&pq)

	for pq.Len() > 0 {
		node := heap.Pop(&pq).(*Node)
		for i := 0; i < len(g[node.Id]); i++ {
			nextId := g[node.Id][i]
			nextDis := node.Dis + c[node.Id][i]
			if nextDis < d[nextId] {
				d[nextId] = nextDis
				heap.Push(&pq, &Node{nextId, nextDis})
			}
		}
	}

	wr := bufio.NewWriter(os.Stdout)
	for i := 0; i < n; i++ {
		wr.WriteString(strconv.Itoa(i))
		wr.WriteString(" ")
		wr.WriteString(strconv.Itoa(d[i]))
		wr.WriteString("\n")
	}
	wr.Flush()
}

C++: #include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
static const int MAX = 10000;
static const int INFTY = (1 << 20);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
 
int n;
vector<pair<int, int> > adj[MAX];
 
void dijkstra() {
    priority_queue<pair<int, int> > PQ;
    int color[MAX];
    int d[MAX];
    for (int i = 0; i < n; i++) {
        d[i] = INFTY;
        color[i] = WHITE;
    }
 
    d[0] = 0;
    PQ.push(make_pair(0, 0));
    color[0] = GRAY;
 
    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 (unsigned int j = 0; j < adj[u].size(); j++) {
            int v = adj[u][j].first;
            if (color[v] == BLACK) continue;
            if (d[v] > d[u] + adj[u][j].second) {
                d[v] = d[u] + adj[u][j].second;
                PQ.push(make_pair(d[v] * (-1), v));
                color[v] = GRAY;
            }
        }
    }
 
    for (int i = 0; i < n; i++) {
        cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
    }
}
 
int main() {
    int k, u, v, c;
 
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            cin >> v >> c;
            adj[u].push_back(make_pair(v, c));
        }
    }
 
    dijkstra();
 
    return 0;
}

C++: #include<cstdio>
#include<queue>
#include<vector>
#include<algorithm>
static const int kMaxVertices = 10000;
static const int kInfinity = 100010;
using namespace std;

void Dijkstra(int n, vector<pair<int, int> > Adjacency_list[], int first_vertex){
	bool has_not_been_added[kMaxVertices];
	int distance[kMaxVertices];
	for (int i = 0; i < n; ++i)	{
		has_not_been_added[i] = true;
		distance[i] = kInfinity;
	}
	distance[first_vertex] = 0;

	priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > PQ;
	PQ.push(make_pair(0, first_vertex));

	while(!PQ.empty()){
		pair<int, int> f = PQ.top(); PQ.pop();
		int u = f.second;
		has_not_been_added[u] = false;
		if (distance[u] < f.first) continue;
		for(vector<pair<int, int> >::iterator it = Adjacency_list[u].begin(); it != Adjacency_list[u].end(); it++){
			int v = (*it).second;
			if(has_not_been_added[v] && distance[u] + (*it).first < distance[v]){
				distance[v] = distance[u] + (*it).first;
				PQ.push(make_pair(distance[v], v));
			}
		}
	}
	for (int i = 0;i < n;++i)
		printf("%d %d\n", i, distance[i]);
}

int main(){
	int number_of_vertices;
	scanf("%d", &number_of_vertices);
	vector<pair<int, int> > Adjacency_list[number_of_vertices];
	for (int vertex_from_i = 0; vertex_from_i < number_of_vertices; ++vertex_from_i)	{
		int vertex_from_id, degree_out;
		scanf("%d %d", &vertex_from_id, &degree_out);
		for (int vertex_to_i = 0; vertex_to_i < degree_out; ++vertex_to_i){
			int vertex_to_id, cost_of_route;
			scanf("%d %d", &vertex_to_id, &cost_of_route);
			Adjacency_list[vertex_from_id].push_back(make_pair(cost_of_route, vertex_to_id));
		}
	}
	Dijkstra(number_of_vertices, Adjacency_list, 0);
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)

const int INF = 1e8;

int n, m; // 頂点の数、辺の数

struct edge {int from, to, cost;}; // 辺の始点・終点・重み

vector<vector<int>> adj_matrix; // 隣接行列
vector<vector<edge>> adj_list; // 隣接リスト

vector<int> dist;
vector<bool> visited;

void dijkstra(int start) {
    dist.resize(n);
    visited.resize(n);
    rep(i, n) {
        if (i == start) dist[i] = 0;
        else dist[i] = INF;
        visited[i] = false;
    }
    priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq;
    pq.push({dist[start], start});
    while (not pq.empty()) {
        int cur = pq.top().second;
        pq.pop();
        visited[cur] = true;
        for (edge e : adj_list[cur]) {
            // int adj = e.to;
            if (visited[e.to] == false) {
                if (dist[e.to] > dist[e.from] + e.cost) {
                    dist[e.to] = dist[e.from] + e.cost;
                    pq.push({dist[e.to], e.to});
                }
            }
        }
    }
}

void solve_ALDS1_12_C() {
    cin >> n;
    adj_list.resize(n);
    rep(i, n) {
        int u, k;
        cin >> u;
        cin >> k;
        rep(j, k) {
            edge e;
            e.from = u;
            cin >> e.to;
            cin >> e.cost;
            adj_list[e.from].push_back(e);
        }
    }
    dijkstra(0);
    rep(i, n) {
        cout << i << " " << dist[i] << endl;
    }
}

int main() {
    // cin >> n;
    // cin >> m;
    // adj_matrix.resize(n, vector<int>(n, INF));
    // rep(i, n) {
    //     adj_matrix[i][i] = 0;
    // }
    // adj_list.resize(n);
    // rep(i, m) {
    //     edge e;
    //     cin >> e.from;
    //     cin >> e.to;
    //     cin >> e.cost;
    //     adj_matrix[e.from][e.to] = e.cost;
    //     adj_list[e.from].push_back(e);
    // }
    solve_ALDS1_12_C();
}