Go: package main

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

const (
	white int = iota
	gray
	black
)

type node struct {
	id     int
	parent int
	edge   []int
	weight []int
	color  int
}

type graph struct {
	nodes    []node
	distance []int
}

var infty = 1 << 32
var null = -1

func constructgraph() *graph {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)

	g := &graph{make([]node, n), make([]int, n)}

	for i := 0; i < n; i++ {
		id := nextInt(sc)
		edges := nextInt(sc)
		n := node{}
		n.id = id
		n.edge = make([]int, edges)
		n.weight = make([]int, edges)
		n.color = white
		for j := 0; j < edges; j++ {
			to := nextInt(sc)
			w := nextInt(sc)
			n.edge[j] = to
			n.weight[j] = w
		}
		g.nodes[id] = n
	}
	return g
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func (g *graph) preparedijkstra(s int) {
	for i := 0; i < len(g.nodes); i++ {
		g.nodes[i].color = white
		g.nodes[i].parent = null
		g.distance[i] = infty
	}
	g.distance[s] = 0
}

func (g *graph) dijkstra(s int) []int {
	g.preparedijkstra(s)

	for {
		var u int
		mincost := infty
		for i, d := range g.distance {
			if g.nodes[i].color != black && mincost > d {
				mincost = d
				u = i
			}
		}

		if mincost == infty {
			break
		}

		g.nodes[u].color = black

		for i, e := range g.nodes[u].edge {
			if g.nodes[e].color != black {
				if g.distance[e] > g.distance[u]+g.nodes[u].weight[i] {
					g.distance[e] = g.distance[u] + g.nodes[u].weight[i]
					g.nodes[e].parent = u
					g.nodes[e].color = gray
				}
			}
		}
	}
	return g.distance
}

func printShortestPath(d []int) {
	for i, v := range d {
		fmt.Printf("%d %d\n", i, v)
	}
}

func main() {
	g := constructgraph()
	d := g.dijkstra(0)
	printShortestPath(d)
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

vector<pint> vp[500001];
int d[100001];
int INF=1000100010;
int n;
int dijkstra(int st){
    priority_queue<pint,vector<pint>,greater<pint> > pq;
    rep(i,n) d[i]=INF;
    d[st]=0;
    pq.push(make_pair(0,st));
    while(!pq.empty()){
        pint pi=pq.top();pq.pop();
        int t=pi.second;
        if(d[t]<pi.first) continue;
        for(auto it:vp[t]){
            if(d[it.second]>d[t]+it.first){
                d[it.second]=d[t]+it.first;
                pq.push(make_pair(d[it.second],it.second));
            }
        }
    }
}
int main(){
    cin>>n;
    int u,k,v,c;
    rep(i,n){
        cin>>u>>k;
        rep(j,k){
            cin>>v>>c;
            vp[u].pb(c,v);
        }
    }
    dijkstra(0);
    rep(i,n){
        cout<<i<<" "<<d[i]<<endl;
    }
    return 0;
}

C++: #include<iostream>
#define INF 1<<21
using namespace std;
static const int N = 101;
int n,A[N][N];
void dikstra(void){
    int d[N],p[N],color[N],minv;
    for(int i=0;i<n;i++){
        d[i] = INF;
        p[i] = -1;
        color[i] = 0;
    }
    d[0] = 0;
    while(1){
        int u =-1;
        minv = INF;
        for(int i=0;i<n;i++){
            if(d[i]<minv && color[i]!=1){
                u = i;
                minv = d[i];
            }
        }
        if(u==-1){
            break;
        }
        color[u] = 1;
        for(int v=0;v<n;v++){
            if(d[u]+ A[u][v] < d[v]){
                d[v] = d[u] + A[u][v];
                p[v] = u;
            }
        }
    }
    for(int i=0;i<n;i++){
        cout << i << ' ' << d[i] << endl;
    }
}
int main(void){
    int u,adj,v;
    cin >> n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            A[i][j] = INF;
        }
    }
    for(int i=0;i<n;i++){
        cin >> u >> adj;
        for(int j=0;j<adj;j++){
            cin >> v >> A[u][v];
        }
    }
    dikstra();
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
static const int MAX = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
static const int INFTY = (1<<21);
int n,M[MAX][MAX];

void dijkstra(){
    int color[MAX],d[MAX],p[MAX];
    int minv;
    for (int i = 0; i < n; i++)
    {
        color[i] = WHITE;
        d[i] = INFTY;
        
    }
    d[0] = 0;color[0] = GRAY;
    while (1)
    {
        minv = INFTY;
        int u = -1;
        for (int i = 0; i < n; i++)
        {
            if(minv>d[i]&&color[i]!=BLACK){
                u = i;
                minv = d[i];
            }
        }
        if(u==-1)break;
        color[u] = BLACK;
        for (int v = 0; v < n; v++)
        {
            if(color[v]!=BLACK&&M[u][v]!=INFTY){
                if(d[v]>d[u]+M[u][v]){
                    d[v] = d[u] + M[u][v];
                    color[v] = GRAY;
                }
            }
        }
    }
    for (int  i = 0; i < n; i++)
        {
            cout << i << " " << (d[i]==INFTY?-1:d[i]) << endl;
        }  
}


int main(){
    cin >> n;
    int u,k,c,v;
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            M[i][j] = INFTY;
        }
    }
    
    
    for (int i = 0; i < n; i++){
        cin >> u >> k;
        for (int j = 0; j < k; j++){
            cin >> v>> c;
            M[u][v] = c;
        }
    }
    dijkstra();
    return 0;
    
}

C++: #include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1LL<<60;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

struct Edge{
    int u;
    int v;
    int cost;

    Edge(int _u, int _v, int c) {
        u = _u;
        v = _v;
        cost = c;
    }
};

vector<Edge> adj;
int dist[110];

int main() {
    int n; cin >> n;
    rep(i, n) {
        int u, k; cin >> u >> k;
        rep(j, k) {
            int v, c; cin >> v >> c;
            adj.emplace_back(Edge(u, v, c));
        }
    }

    // 初期化
    rep(i, n) {
        dist[i] = (i == 0) ? 0 : INT_INF;
    }

    for (int i = 1; i < n; i++) {
        for (auto edge: adj) {
            int u = edge.u;
            int v = edge.v;
            int c = edge.cost;
            // cout << '(' << u << ',' << v << ',' << c << ')' << endl;
            if (dist[u] != INT_INF && dist[v] > dist[u] + c) {
                dist[v] = dist[u] + c;
            }
        }
    }

    rep(i, n) {
        cout << i << ' ' << dist[i] << endl;
    }
}