Go: package main

import (
	"fmt"
	"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)

	g := make([][]int, n)
	c := make([][]int, n)
	pq := make(PriorityQueue, 0, n)
	d := make([]int, n)
	for i := 0; i < n; i++ {
		var u,k int
		fmt.Scan(&u)
		fmt.Scan(&k)
		g[u] = make([]int, k)
		c[u] = make([]int, k)
		for j := 0; j < k; j++ {
			fmt.Scan(&g[u][j])
			fmt.Scan(&c[u][j])
		}

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

	for i := 0; i < n; i++ {
		fmt.Println(i, d[i])
	}
}

C++: #include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <set>
#include <map>
#include <deque>
#define NMAX 100
#define INF 100000000

//??????????????¢??????????????¨debug()??????????????????
#define DEBUG

using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef pair<int ,int > P;
typedef long long ll;

int N,ans = 0;
int d[NMAX] = {};
vector<P> connect[NMAX];

void solve(){
	d[0] = 0;
	priority_queue<P, vector<P>, greater<P> > que;
	que.push(P(0,0));
	while(!que.empty()){
		P p = que.top();
		// cout << "P(" << p.first << "," << p.second << ")\n";
		que.pop();
		int v = p.first;
		if(d[v] < p.second) continue;
		for (int i = 0; i < connect[v].size(); ++i)
		{
			if(d[connect[v][i].first] > d[v] + connect[v][i].second){
				d[connect[v][i].first] = d[v] + connect[v][i].second;
				que.push(P(connect[v][i].first,d[connect[v][i].first]));
			}
		}
	}
}

void debug(){

}

void answer(){
	for (int i = 0; i < N; ++i)
	{
		cout << i << " " << d[i] << "\n";
	}
}

int main(){
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		int a,b;
		cin >> a >> b;
		for (int j = 0; j < b; ++j)
		{
			int k,l;
			cin >> k >> l;
			connect[a].push_back(P(k,l));
		}
	}
	Fill(d,INF);
	solve();
	#ifdef DEBUG
	debug();
	#endif
	answer();

	return 0;
}

C++: #include <stdio.h>
#include <vector>
#include <list>
#include <map>
#include <array>
#include <memory>
#include <string>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <unordered_map>
#include <stdexcept>
#include <numeric>
#include <queue>

using std::string;
using std::vector;


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// util
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

std::vector<std::string> split(const std::string& input, char delimiter)
{
    std::istringstream stream(input);

    std::string field;
    std::vector<std::string> result;
    while (std::getline(stream, field, delimiter)) {
        result.push_back(field);
    }
    return result;
}



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// user func
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void printList(const vector<int>& list) {
    // print
    for(int i = 0; i < list.size(); i++){
        printf("%d", list[i]);
        if ( i + 1 != list.size() ) {
            printf(" ");
        }
    }
    printf("\n");
}



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// logic
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

static int MAX = 1000000;

class Node{
public:
    Node(int id, int numEdge)
     : id(id)
     , edges(vector<int>(numEdge, MAX))
    {
        // constructer
    }
    
    void Edge(int id, int weight){
        this->edges[id] = weight;
    }

    vector<int> Edges() {
        return this->edges;
    }

    int id;
    bool done = false;
    vector<int> edges;
};

class List{
public:
    // constructer
    List(int numNode)
        : results(numNode)
    {
        for (int i = 0; i < numNode; i++) {
            this->nodes.push_back(Node(i, numNode));
            this->results[i] = MAX;
        }
    }

    void SetWeight(int from, int to, int weight)
    {
        this->nodes[from].Edge(to, weight);
    }
    
    vector<int> ShortedPath() {
        // this->Enqueue(0);
        this->results[0] = 0;
        this->queue.push(0);
        this->Traverse();
        return this->results;
    }

    void Traverse() {
        while(!this->queue.empty()) {
            int queueIndex = queue.front();
            queue.pop();
            vector<int> edges = this->nodes[queueIndex].Edges();
            for (int i = 0; i < edges.size(); i++) {
                // update result
                int myWeight = this->results[queueIndex];
                this->results[i] = std::min(this->results[i], myWeight + edges[i]);
            }
            // printList(this->results);
            // enqueue
            this->Enqueue(queueIndex);
            // done flag
            this->nodes[queueIndex].done = true;
        }
    }

    void Enqueue(int index) {
        // copy weights
        if (this->nodes[index].done) return;
        std::list<std::pair<int, int>> weights;
        for (int i = 0; i <  this->nodes[index].Edges().size(); i++) {
            weights.push_back(std::make_pair(i, this->nodes[index].Edges()[i]));
        }
        // sort
        weights.sort([](auto& lhs, auto& rhs){
            return lhs.second < rhs.second;
        });
        // enqueue
        for (auto weight : weights){
            queue.push(weight.first);
        }
    }
    
    

    void Print() {
        for (int i = 0; i < this->nodes.size(); i++) {
            printf("%d: ", i);
            for (int j = 0; j < this->nodes[i].Edges().size(); j++) {
                printf("%d (%d) ", j, this->nodes[i].Edges()[j]);
            }
            printf("\n");
        }
    }
private:
    std::queue<int> queue;
    std::vector<int> results;
    vector<Node> nodes;
};

void solve() {

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

    for (int i = 0; i < n; i++){
        int key;
        scanf("%d", &key);
        int k;
        scanf("%d", &k);
        for (int j = 0; j < k; j++) {
            int dest;
            int weight;
            scanf("%d %d", &dest, &weight);
            list.SetWeight(key, dest, weight);
        }
    }
    // list.Print();
    auto result = list.ShortedPath();
    for(int i = 0; i < result.size(); i++) {
        printf("%d %d\n", i, result[i]);
    }
}

void test(){

}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// main
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main() {
    solve();
    // test();
    return 0;
}