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 <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <limits>
#include <cmath>
#include <numeric>
#include <string>

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
#define rep(i, a, b) for(int i = (a); i < (b); ++i )
#define rrep(i, a, b) for(int i = (a); i > (b); --i )
#define REP(i, a, b) for(int i = (a); i <= (b); ++i )
#define RREP(i, a, b) for(int i = (a); i >= (b); --i )
#define llrep(i, a, b) for(ll i = (a); i < (b); ++i )
#define llrrep(i, a, b) for(ll i = (a); i > (b); --i )
#define llREP(i, a, b) for(ll i = (a); i <= (b); ++i )
#define llRREP(i, a, b) for(ll i = (a); i >= (b); --i )
#define ullrep(i, a, b) for(ull i = (a); i < (b); ++i )
#define ullrrep(i, a, b) for(ull i = (a); i > (b); --i )
#define ullREP(i, a, b) for(ull i = (a); i <= (b); ++i )
#define ullRREP(i, a, b) for(ull i = (a); i >= (b); --i )

class UnionFind {
public:
    UnionFind(unsigned long long n) : rank_(n, 0), p_(n, 0) {
        rep(i, 0, n) {
            MakeSet(i);
        }
    }

    void MakeSet(int x) {
        p_[x] = x;
        rank_[x] = 0;
    }

    bool Same(int x, int y) {
        return FindSet(x) == FindSet(y);
    }

    void Link(int x, int y) {
        if (rank_[x] > rank_[y]) {
            p_[y] = x;
        } else {
            p_[x] = y;
            if (rank_[x] == rank_[y]) {
                rank_[y]++;
            }
        }
    }

    void Unite(int x, int y) {
        Link(FindSet(x), FindSet(y));
    }

    int FindSet(int x) {
        if (x != p_[x]) {
            p_[x] = FindSet(p_[x]);
        }
        return p_[x];
    }

private:
    std::vector<int> rank_, p_;
};

int N, Q;

int G[100][100];
int d[100];
int p[100];
int c[100];

int main() {
    cin >> N;
    rep(i, 0, N) {
        rep(j, 0, N) {
            G[i][j] = 10000010;
        }
    }
    rep(i, 0, N) {
        int u, k;
        cin >> u >> k;
        rep(j, 0, k) {
            int t, d;
            cin >> t >> d;
            G[u][t] = d;
        }
    }
    rep(i, 0, N) {
        d[i] = numeric_limits<int>::max();
    }

    d[0] = 0;
    p[0] = 0;
    while (true) {
        int m = -1;
        int min_d = numeric_limits<int>::max();
        rep(i, 0, N) {
            if ((c[i] == 0) && (min_d > d[i])) {
                min_d = d[i];
                m = i;
            }
        }
        if (m < 0) {
            break;
        }
        c[m] = 1;
        rep(i, 0, N) {
            if ((d[m] + G[m][i]) < d[i]) {
                d[i] = d[m] + G[m][i];
                p[i] = m;
            }
        }
    }
    rep(i, 0, N) {
        cout << i << " " << d[i] << endl;
    }
}

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

class Vertice;
class Edge;

class Vertice{
private:
	int id;
	int edge_num;
	int *vertice_id_list;
	Edge **edges;
	bool flag_fixed;
	int distance_min;
public:
	Vertice(int id, int edge_num_max);
	~Vertice(){ delete[] edges, vertice_id_list; }
	int getDistanceMin() const { return distance_min; }
	void addEdge(int vertice_id, Edge *edge);
	void addVertices(Vertice *vertices[]);
	void setDistance(int d);
	void serveDistance();
	void setFlagFixed(){ flag_fixed = true; }
};

class Edge{
private:
	int distance;
	Vertice *vertice;
public:
	Edge(int distance){ this->distance = distance; }
	void addVertice(Vertice *vertice){ this->vertice = vertice; }
	void setDistance(int distance){ vertice->setDistance(distance + this->distance); }
};

struct verticeComp {
	bool operator()(const Vertice *v1, const Vertice *v2)
	{
		return v1->getDistanceMin() > v2->getDistanceMin();
	}
};

priority_queue<Vertice*, vector<Vertice*>, verticeComp> PQ; 

Vertice::Vertice(int id, int edge_num_max)
{
	this->id = id;
	edge_num = 0;
	vertice_id_list = new int[edge_num_max];
	edges = new Edge*[edge_num_max];
	flag_fixed = false;
	distance_min = 1000000;
}

void Vertice::addEdge(int vertice_id, Edge *edge)
{
	edges[edge_num] = edge;
	vertice_id_list[edge_num] = vertice_id;
	edge_num++;
}

void Vertice::addVertices(Vertice *vertices[])
{
	for (int i = 0; i < edge_num; i++) {
		edges[i]->addVertice(vertices[vertice_id_list[i]]);
	}
}

void Vertice::setDistance(int d)
{
	if (flag_fixed) return;
	if (d < distance_min) distance_min = d;
	PQ.push(this);
}

void Vertice::serveDistance()
{
	for (int i = 0; i < edge_num; i++) {
		edges[i]->setDistance(distance_min);
	}
	if (PQ.empty()) return;
	Vertice *fixed_vertice = PQ.top();
	PQ.pop();
	fixed_vertice->setFlagFixed();
	fixed_vertice->serveDistance();
}

int main(void)
{
	Vertice **vertices;

	int n;
	cin >> n;
	vertices = new Vertice*[n];
	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		vertices[u] = new Vertice(u, k);
		for (int j = 0; j < k; j++) {
			int v, c;
			cin >> v >> c;
			vertices[u]->addEdge(v, new Edge(c));
		}
	}

	for (int i = 0; i < n; i++) {
		vertices[i]->addVertices(vertices);
	}

	vertices[0]->setDistance(0);
	vertices[0]->setFlagFixed();
	PQ.pop();
	vertices[0]->serveDistance();

	for (int i = 0; i < n; i++) {
		cout << i << " ";
		cout << vertices[i]->getDistanceMin() << endl;
	}

	return 0;
}

C++: /*宣言*/
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<string.h>
#include<string>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
int main()
{
	int n, u, k, w[101][101], v, c;
	int d[101], kas[101] = { 0 }, K;
	cin >> n;
	memset(d, 0x7f, sizeof(d));
	memset(w, 0x7f, sizeof(w));
	rep(i, n)
	{
		cin >> u >> k;
		rep(j, k)
		{
			cin >> v >> c;
			w[u][v] = c;
		}
	}
	d[0]=0;
	int p[101];
	int Min,Min1;
	Min = 0;
	Min1 = 0x7f;
	kas[0] = 1;
	rep(j, n)
	{
		rep(i, n)
		{
			if (d[i] > d[Min] + w[Min][i])
			{
				d[i] = d[Min] + w[Min][i];
				p[i] = Min;
			}
			if (Min1 > d[i] && kas[i] == 0)
			{
				Min1 = d[i];
				K = i;
			}
		}
		kas[K] = 1;
		Min = K;
		Min1 = 100000000;
	}
	rep(i, n)
	{
		cout << i <<' '<< d[i] << endl;
	}
	return 0;
}