Go: package main

import (
	"strconv"
	"fmt"
	"bufio"
	"os"
)
const INF = 1 << 21
var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}


func main() {
	scanner.Split(bufio.ScanWords)
	n := nextInt()
	adj := make([][]int, n)
	for i := range adj {
		adj[i] = make([]int, n)
	}

	for i := 0;i < n; i++ {
		u := nextInt()
		k := nextInt()
		for j := 0; j < k; j++ {
			v := nextInt()
			c := nextInt()
			adj[u][v] = c
		}
	}

	// for i := range adj {
	// 	fmt.Println(adj[i])
	// }

	dist := make([]int, n)
	prev := make([]int, n)
	visited := make([]bool, n)
	dijkstra := func(start int, size int) {
		for i := 0; i < size; i++ {
			dist[i] = INF
			prev[i] = -1
			visited[i] = false
		}
		dist[start] = 0
		for {
			u := -1
			tmp_min := INF
			for i := 0; i < size; i++ {
				if visited[i] == false && dist[i] < tmp_min {
					tmp_min = dist[i]
					u = i
				}
			}
			if u == -1 {
				break
			}
			visited[u] = true
			for i := 0; i < size; i++ {
				if adj[u][i] > 0 {
					w := adj[u][i]
					newlen := dist[u] + w
					if newlen < dist[i] {
						dist[i] = newlen
						prev[i] = u
					}
				}
			}
		}
	}
	dijkstra(0, n)
	for i, cost := range dist {
		fmt.Printf("%d %d\n", i, cost)
	}
}

C++: #include<iostream>
using namespace std;
#define max 100
#define infty 1<<21

int n;
int d[max];
int aa[max][max];
int color[max];

void soya() {
	d[0] = 0;
	while (1) {
		int x = infty;
		for (int i = 0; i < n; i++) {
			if (x != infty) {
				if (d[i] < d[x] && color[i] != 2) {
					x = i;
				}
			}
			else {
				if (d[i] < x && color[i] != 2) {
					x = i;
				}
			}
		}

		if (x == infty) break;
		else {
			color[x] = 2;
			for (int i = 0; i < n; i++) {
				if (aa[x][i] != -1 && d[x] + aa[x][i] < d[i]) {
					d[i] = d[x] + aa[x][i];
				}
			}
		}
	}
}

int main() {
	for (int i = 0; i < max; i++) {
		color[i] = 0;
		d[i] = infty;
	}

	for (int i = 0; i < max; i++) {
		for (int j = 0; j < max; j++) {
			aa[i][j] = -1;
		}
	}

	cin >> n;
	for (int i = 0; i < n; i++) {
		int id;
		int k;
		cin >> id >> k;
		for (int j = 0; j < k; j++) {
			int num1;
			int kyori;
			cin >> num1 >> kyori;
			aa[id][num1] = kyori;
		}
	}

	soya();

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

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i,a,b) for(i=a;i<b;i++)
#define rloop(i,a,b) for(i=a;i>=b;i--)
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
const int inf=1000000001;
const ll INF=1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
static const int WHITE=0;
static const int GRAY=1;
static const int BLACK=2;
static const int N=100;

int n;
vii m(N,vi(N));
vi d(N,inf);

void dijkstra();

int main(){
	int i,j;
	cin>>n;
	int u,k,v,c;
	loop(i,0,n){
		loop(j,0,n){
			m[i][j]=inf;
		}
	}
	loop(i,0,n){
		cin>>u>>k;
		loop(j,0,k){
			cin>>v>>c;
			m[u][v]=c;
		}
	}
	dijkstra();
	loop(i,0,n){
		cout<<i<<" "<<d[i]<<endl;
	}
}

void dijkstra(){
	int i;
	d[0]=0;
	vi color(n,WHITE);
	color[0]=BLACK;
	int u=0;
	while(1){
		int minv=inf,v=-1;
		loop(i,0,n){
			if(color[i]!=BLACK){
				d[i]=min(d[i],d[u]+m[u][i]);
				if(minv>d[i]){
					minv=d[i];
					v=i;
				}
			}
		}
		if(v==-1){
			break;
		}
		color[v]=BLACK;
		u=v;
	}
	
}

C++: #include <iostream>
using namespace std;
#include <algorithm>
#include <string>
#define INF 1000000

int flg[100];

bool check(int p){

	if (flg[p] == 1) return false;
	return true;
}

int main(void){

	int n;

	cin >> n;
	int u, k;
	int date[100][100]; //date[??????????????????][?????´?????????]
	int dis[100]; //0????????????????????????????????¢

	memset(date, INF, sizeof(date));
	memset(dis, INF, sizeof(dis));
	memset(flg, 0, sizeof(flg));
	date[0][0] = 0;
	dis[0] = 0;
	for (int i = 0; i < n; i++){

		cin >> u >> k;
		for (int j = 0; j < k; j++){

			int v, c;
			cin >> v >> c;
			date[u][v] = c;
		}
	}

	while(1){
		int mini = INF;
		int p = -1;
		for (int i = 0; i < n; i++){
			if (check(i) && mini > dis[i]){
				p = i;
				mini = dis[i];
			}
		}
		if (p == -1) break;
		flg[p] = 1;
		for (int i = 0; i < n; i++){
			if (check(i) && dis[i] > dis[p] + date[p][i]){
				dis[i] = dis[p] + date[p][i];
			}
		}
	}

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

C++: #define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<functional>
#include<algorithm>
#include<stack>
#include<queue>
#include<iomanip>
#include<set>
#include<map>
#include<utility>
#include<string>
#include<vector>

using namespace std;

#define LL long long
const int dx[4] = { 1,-1,0,0 };
const int dy[4] = { 0,0,1,-1 };
bool OOA(int x, int y, int H, int W) { return (0 <= x && x<H) && (0 <= y && y<W); }

struct Edge{
	int fr,to,val;
	bool operator < (Edge x){
		return (val<x.val);
	}
};

struct Graph {
	struct Edge {
		int fr, to, val;
		Edge(int f, int t, int v) :fr(f), to(t), val(v) {}
	};

	int V, E, t;
	vector<int>cost;
	vector<bool>vzt;
	vector<vector<pair<int,int>>>adj;//to,val
	void init(int n,int dflt) {//dflt!=0
		t = 1;
		V = n;
		adj = vector<vector<pair<int,int>>>(V + 1);
		cost = vector<int>(V + 1, dflt);
		vzt = vector<bool>(V + 1, false);
		return;
	}

	void Dijkstra(int s){
		priority_queue<pair<int,int>>pq;
		pq.push({s,0});
		cost[s]=0;
		while(!pq.empty()){
			auto now=pq.top().first,ncos=pq.top().second;
			pq.pop();
			for(int i=0;i<adj[now].size();i++){
				if(cost[adj[now][i].first]>cost[now]+adj[now][i].second){
					cost[adj[now][i].first]=cost[now]+adj[now][i].second;
					pq.push({ adj[now][i].first,cost[adj[now][i].first] });
				}
			}
		}
		return;
	}
};

int n;
Graph G;

int main() {
	cin >> n;
	G.init(n,(1<<30));
	for(int i=0;i<n;i++){
		int u,k;
		cin>>u>>k;
		for(int j=0;j<k;j++){
			int v,c;
			cin>>v>>c;
			G.adj[u].push_back({v,c});
		}
	}
	G.Dijkstra(0);
	for(int i=0;i<n;i++){
		cout<<i<<" "<<G.cost[i]<<endl;
	}
	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <list>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <iomanip>
#define INF 1050000000
 
using namespace std;

#define MAX_V 101

int d[MAX_V][MAX_V];  // d[u][v]は辺e=(u,v)のコスト(存在しない場合はINF、ただしd[i][i]=0とする)
int V;                // 頂点数
void warshall_floyd(int n) {
	V = n;

	for (int i = 0; i < V; i++)
		for (int j = 0; j < V; j++) 
			for (int k = 0; k < V; k++)
				d[0][j] = min(d[0][j], d[0][k] + d[k][j]);
}

int main(void)
{
	int n, u, v, k, c;

	cin >> n;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i == j) d[i][j] = 0; 
			else d[i][j] = INF;
		}
	}

	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			cin >> v >> c;
			d[u][v] = c;
		}
	}
	
	warshall_floyd(n);

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


	return (0);
}

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <bitset>

using namespace std;

int main()
{
	int N;
	cin>>N;
	bitset<100> data(1);
	
	vector<vector<int> > cost(N,vector<int>(N,100001));
	cost[0][0]=0;
	pair<int,int> ddata;
	for(int i=0;i<N;i++){
		int u,k;
		cin>>u>>k;
		for(int j=0;j<k;j++){
			cin>>ddata.first>>ddata.second;
			cost[u][ddata.first]=ddata.second;
		}
	}
	//
	int n;
	for(int i=0;data.count()<N;i=n){
		n=1;
		for(int j=1;j<N;j++){
			if(i!=j&&cost[0][j]>cost[0][i]+cost[i][j]){
				cost[0][j]=cost[0][i]+cost[i][j];
			}
			if((!data[j]&&cost[i][j]<cost[i][n])||i==n){
				n=j;
			}
		}
		data.set(n);
	}
	for(int i=0;i<N;i++){
		cout<<i<<' '<<cost[0][i]<<endl;
	}
	return 0;
}