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 <cstdio>
#include <cstdlib>
#include <stack>
#include <vector>
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstring>
#include <queue>
#include <string>

using namespace std;

const double PI = 3.14159265358979;

//int G[101][101];
int visited[10001];
int n;

int d[10001];


struct Vertex {
	int u;
	int weight;

	friend bool operator < (Vertex a, Vertex b) {
		return a.weight > b.weight;
	}
};

vector<Vertex> G[10001];

void dijkstra(int start) {

	priority_queue<Vertex> PQ;

	for (int i = 0; i < n; i++)	{
		d[i] = INT_MAX;
	}

	d[start] = 0;
	PQ.push(Vertex{ 0,0 });

	while (!PQ.empty()) {
		Vertex f = PQ.top();
		PQ.pop();
		int u = f.u;
		if (visited[u]) {
			continue;
		}
		else {
			visited[u] = 1;
		}

		//if (f.weight > d[u]) continue;

		
		for (int j = 0; j < G[u].size(); j++)
		{
			int v = G[u][j].u;
			if (!visited[v]) {
				if (d[u] + G[u][j].weight < d[v]) {
					PQ.push(Vertex{ v, d[u] + G[u][j].weight });
					d[v] = d[u] + G[u][j].weight;
				}
			}
		}
	}


}

int main() {
	
	
	cin >> n;

	for (int i = 0; i < n; i++)	{
		int u, k; cin >> u >> k;
		for (int j = 0; j < k; j++)	{
			int v, w; cin >> v >> w;
			G[u].push_back(Vertex{ v, w });
		}
	}

	dijkstra(0);

	for (int i = 0; i < n; i++)	{
		cout << i << " " << d[i] << endl;
	}

	return 0;
}

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

#define MAX_NODE 10000
#define INF 1000000000

using namespace std;

struct Edge {
	int to, w;
};

typedef pair<int, int> P;

vector<Edge> adj[MAX_NODE];
int d[MAX_NODE];

void dijkstra(int n, int start) {
	priority_queue<P, vector<P>, greater<P> > heap;
	fill(d, d + n, INF);
	d[start] = 0;
	heap.push({0, start});

	while (!heap.empty()) {
 		P p = heap.top();
 		heap.pop();
 		int from = p.second;
 		if (d[from] < p.first)
 			continue;
 		for (int i = 0; i < adj[from].size(); i++) {
 			Edge e = adj[from][i];
	 		if (d[from] + e.w < d[e.to]) {
	 			d[e.to] = d[from] + e.w;
	 			heap.push( {d[e.to], e.to} );
	 		}
	 	}
	}
}

int main(){
	int n,u,k,c,v;
	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({v,c});
		}
	}
	dijkstra(n,0);
	for(int i=0;i<n;i++){
		cout<<i<<" "<<d[i]<<"\n";
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
int n;
/*
int dat[100][100];
int cost[100];
int done[100];

void prim(){
	for(int i=0;i<n;i++){
		cost[i]=1<<21;
		done[i]=0;
	}
	int s=0;	
	int next, ncost=1<<21;
	done[s]=1;
	cost[s]=0;
	while(1){
		ncost=1<<21;
		for(int j=0;j<n;j++){
			if(done[j]){
				for(int i=0;i<n;i++){
					if(dat[j][i]!=-1){
						if(cost[i]>=dat[j][i]&&!done[i]){
							cost[i]=dat[j][i];
						}
						if(ncost>cost[i]&&!done[i]){
							next=i;
							ncost=cost[i];
						}
					}
				}
			}
		}
//		cout<<"next:"<<next<<" cost:"<<cost[next]<<endl;
		done[next]=1;
		int flag=true;
		for(int i=0;i<n;i++){
			if(!done[i]) flag = false;
		}
		if(flag)
			return;
	}
}


void dijk(){
	for(int i=0;i<n;i++){
		cost[i]=1<<21;
		done[i]=0;
	}
	int s=0;	
	int next, ncost=1<<21;
	done[s]=1;
	cost[s]=0;
	while(1){
		ncost=1<<21;
		for(int j=0;j<n;j++){
			if(done[j]){
				for(int i=0;i<n;i++){
					if(dat[j][i]!=0){
						if(cost[i]>=dat[j][i]+cost[j]){
							cost[i]=dat[j][i]+cost[j];
						}
						if(ncost>cost[i]&&!done[i]){
							next=i;
							ncost=cost[i];
						}
					}
				}
			}
		}
//		cout<<"next:"<<next<<" cost:"<<cost[next]<<endl;
		done[next]=1;
		int flag=true;
		for(int i=0;i<n;i++){
			if(!done[i]) flag = false;
		}
		if(flag)
			return;
	}
}
*/

vector<vector<int> > dat;
int cost[10000];
int done[10000];

void dijk2(){
	for(int i=0;i<n;i++){
		cost[i]=1<<21;
		done[i]=0;
	}
	int s=0;	
	int next, ncost=1<<21;
	done[s]=1;
	cost[s]=0;
	while(1){
		top:
		ncost=1<<21;
		for(int j=0;j<n;j++){
			if(done[j]){
				for(int i=0;i<n;i++){
					if(dat[j][i]!=0){
						if(!done[i]){
							if(cost[i]>=dat[j][i]+cost[j]){
								cost[i]=dat[j][i]+cost[j];
							}
							if(ncost>cost[i]){
								next=i;
								ncost=cost[i];
							}
						}
					}
				}
			}
		}
//		cout<<"next:"<<next<<" cost:"<<cost[next]<<endl;
		done[next]=1;
		for(int i=0;i<n;i++){
			if(!done[i]) goto top;
		}
		return;
	}
}



int main(){
	int num, from, dist, c;
	cin>>n;	
	dat.reserve(n);
	for(int i=0;i<n;i++){
		vector<int> d(n);
		dat.push_back(d);
	}
	for(int i=0;i<n;i++){
		cin>>from>>num;
		for(int j=0;j<num;j++){
			cin>>dist>>c;
			dat[from][dist]=c;
		}
	}
	dijk2();
	for(int i=0;i<n;i++){
		cout<<i<<" "<<cost[i]<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

vector<int> adja[10000], cost[10000];

#define INF (1 << 30)

int main() {
	int n, id, k;

	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> id >> k;
		adja[id].resize(k);
		cost[id].resize(k);
		for (int j = 0; j < k; ++j) {
			cin >> adja[id][j] >> cost[id][j];
		}
	}

	priority_queue<pair<int, int>> que;
	que.push(make_pair(0, 0)); //cost, node
	int best[10000];
	fill(best, best + n, INF);
	best[0] = 0;

	while (!que.empty()) {
		pair<int, int> top = que.top();
		que.pop();

		if (best[top.second] < top.first) {
			continue;
		}

		for (int j = 0, len = adja[top.second].size(); j < len; ++j) {
			if (best[adja[top.second][j]] > top.first + cost[top.second][j]) {
				best[adja[top.second][j]] = top.first + cost[top.second][j];
				que.push(make_pair(top.first + cost[top.second][j], adja[top.second][j]));
			}
		}
	}

	for (int i = 0; i < n; ++i) {
		cout << i << " " << best[i] << endl;
	}

	return 0;
}