Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

const T = 10000000

var n int
var A [101][101]int

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func Shortestsearch() {
	var Minimum int
	var d, color [100]int
	var u int

	for i := 0; i < n; i++ {
		d[i] = T
		color[i] = 0
	}

	d[0] = 0
	color[0] = 1

	for {
		Minimum = T
		u = -1
		for i := 0; i < n; i++ {
			if Minimum > d[i] && color[i] != 2 {
				u = i
				Minimum = d[i]
			}
		}
		if u == -1 {
			break
		}
		color[u] = 2
		for j := 0; j < n; j++ {
			if color[j] != 2 && A[u][j] != T {
				if d[j] > d[u]+A[u][j] {
					d[j] = d[u] + A[u][j]
					color[j] = 1
				}
			}
		}
	}
	for i := 0; i < n; i++ {
		fmt.Printf("%d %d\n", i, d[i])
	}
}
func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()

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

C++: #include<iostream>
#include<vector>
using namespace std;
const int MAX = 100;
const int INF = 200000;
int n, G[MAX][MAX];
int dis[MAX];
bool book[MAX] = { false };
void init()
{
	for (int i = 0; i < n; i++)
		dis[i] = G[0][i];
	book[0] = true;
}
void dijkstra()
{
	for (int k = 1; k <= n - 1; k++)
	{
		int min = INF;
		int u;
		for (int j = 0; j < n; j++)
			if (dis[j] > 0 && dis[j] < INF && !book[j] && dis[j] < min)
			{
				min = dis[j];
				u = j;
			}
		book[u] = true;
		for (int v = 0; v < n; v++)
			if (!book[v] && dis[u]+G[u][v] < dis[v])
				dis[v] = dis[u] + G[u][v];
	}
}
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			if (i != j)
				G[i][j] = INF;
			else
				G[i][j] = 0;
	for (int i = 0; i < n; i++)
	{
		int u, d;
		cin >> u >> d;
		for (int j = 0; j < d; j++)
		{
			int v, w;
			cin >> v >> w;
			G[u][v] = w;
		}
	}
	init();
	dijkstra();
	for (int i = 0; i < n; i++)
		cout << i << " " << dis[i] << endl;
}

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

int INF = 900000000;
using pii = std::pair<int, int>;
std::vector<std::vector<pii>> g;
std::vector<bool> visited; 
std::vector<int> c; 
std::priority_queue<pii, std::vector<pii>, std::greater<pii>> q;

int n, p, x, y;
int discard;


int main() {
    std::cin >> n;
    visited.assign(n, false);
    g.assign(n, std::vector<pii>(0));
    c.assign(n, INF);
    for (int i = 0; i < n; i++) {
        std::cin >> discard >> p;
        for (int k = 0; k < p; k++) {
            std::cin >> x >> y;
            g[i].push_back(std::make_pair(y, x));
        }
    }
    q.push(std::make_pair(0, 0));
    c[0] = 0;
    while (!q.empty()) {
        auto e = q.top();
        q.pop();
        for (int j = 0; j < g[e.second].size(); j++) {
            if (c[g[e.second][j].second] < g[e.second][j].first) {
                continue;
            }
            if (c[e.second]+g[e.second][j].first < c[g[e.second][j].second]) {
                c[g[e.second][j].second] = c[e.second]+g[e.second][j].first;
                q.push(g[e.second][j]);
            }
        }
    }
    for (int i = 0; i < n; i++) {
        std::cout << i << " " << c[i] << std::endl;
    }
}

C++: #include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;

#define M 10005
#define INF 0x3f3f3f3f

int d[M][M],a[M],n;
bool vis[M];

void dijkstra()
{
    printf("%d!\n",n);
    for(int i=0;i<n;i++){
        if(i == 0) a[i]=0;
        else a[i]=INF;
    }
    memset(vis,0,sizeof(vis));
    for(int i=0;i<n;i++){
        int mark=-1,minn=INF;
        for(int j=0;j<n;j++){
            if(!vis[j]&&a[j]<minn){
                minn=a[j];
                mark=j;
            }
        }
        vis[mark]=1;
        for(int j=0;j<n;j++){
            if(!vis[j]){
                a[j]=min(a[j],a[mark]+d[mark][j]);
            }
        }
    }
    for(int i=0;i<n;i++){
        printf("%d %d\n",i,a[i]);
    }
}

int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(j == i)
                d[i][j]=0;
            else
                d[i][j]=INF;
        }
    }
    for(int j=0;j<n;j++){
        int u,k;
        scanf("%d%d",&u,&k);
        for(int i=0;i<k;i++){
            int v,w;
            scanf("%d%d",&v,&w);
            d[u][v]=w;
        }
    }
    dijkstra();
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (ll)(1E9+7)
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}

#define MAX_V 100

struct edge {
	edge(int a, int b) {
		cost = a;
		to = b;
	}
	int cost;
	int to;
};

int n;
vector<vector<edge>> G;
vector<int> d;

void dijkstra(int s) {
	priority_queue<pii, vector<pii>, greater<pii>> que;
	d[s] = 0;
	que.push(pii(0, s));

	while (!que.empty()) {
		pii p = que.top();
		que.pop();
		int v = p.second;
		if (d[v] < p.first) continue;
		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(pii(d[e.to], e.to));
			}
		}
	}

}

int main() {
	int n,u,k,tmpp,tmpw;
	cin >> n;
	d = vector<int>(n, INF);
	G = vector<vector<edge>>(n);
	rep (i,n) {
		cin >> u >> k;
		rep(j, k) {
			cin >> tmpp>>tmpw;
			G[u].emplace_back(tmpw, tmpp);
		}
	}
	dijkstra(0);
	rep(i, n) {
		cout << i << " " << d[i] << endl;
	}
}

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;
	
	vector<vector<int> > cost(N,vector<int>(N,10000001));
	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;
		}
	}
	//
	
	vector<int> maxcost(N,10000001);
	
	priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>> > que;
	
	que.push(pair<int,int>(0,0));
	
	while(!que.empty()){
		int n=que.top().second;
		if(que.top().first<maxcost[n]){
			maxcost[n]=que.top().first;
		}
		for(int j=1;j<N;j++){
			if(que.top().first+cost[n][j]<maxcost[j]){
				maxcost[j]=que.top().first+cost[n][j];
				ddata.first=que.top().first+cost[n][j];
				ddata.second=j;
				que.push(ddata);
			}
		}
		que.pop();
	}
	
	for(int i=0;i<N;i++){
		cout<<i<<' '<<maxcost[i]<<endl;
	}
	return 0;
}