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 <cstdio>
#include <cctype>
#include <climits>
#include <vector>
#include <queue>
using namespace std;

#define si static inline
#define gcu getchar_unlocked
si int in() {
	int c, n = 0;
	bool minus = false;
	if ((c = gcu()) == '-') minus = true; else ungetc(c, stdin);
	while ((c = gcu()) >= '0' && c <= '9') n = 10 * n + (c - '0');
	//return n; }
	return minus ? -n : n; }
si void scan(char *s) {while (!isspace(*s++ = gcu()));}
#define pcu putchar_unlocked
#define svo si void out
template <typename T>
svo(T n) {
	static char buf[20];
	char *p = buf;
	//if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
svo(const char *s){while(*s)pcu(*s++);}
svo(char *s){while(*s)pcu(*s++);}
svo(char c){pcu(c);}
template <typename T>
//svo(vector<T> &v){for(T &x:v)out(' '),out(x);out('\n');}
svo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
template <typename head, typename... tail>
svo(head&& h, tail&&... t){out(h);out(move(t)...);}
#undef svo
#undef si

#define v vector
struct graph {
	struct node {int n, w;};
	v<v<node>> nodes;

	void read(int n) {
		nodes.resize(n);
		for (auto &x: nodes) {
			in();
			for (int k = in(); k--;) {
				int c = in();
				x.push_back({c, in()});
			}
		}
	}

	v<node> dks() {
		v<node> w(nodes.size(), {0, INT_MAX});
		w[0].w = 0;
		priority_queue<node> q;
		q.push({0, 0});
		while (!q.empty()) {
			node n = q.top();
			q.pop();
			if (w[n.n].n)
				continue;
			w[n.n].n = 1;
			for (node &x: nodes[n.n]) {
				w[x.n].w = min(w[x.n].w, n.w + x.w);
				q.push({x.n, w[x.n].w});
			}
		}
		return move(w);
	}
};

bool operator < (const graph::node &a, const graph::node &b) {
	return a.w > b.w;
}

int main() {
	graph g;
	g.read(in());
	int i = 0;
	for (auto &x: g.dks())
		out(i++, ' ', x.w, '\n');
}

C++: #include <iostream>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#include <cmath>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)

#define debug(x) cerr<<#x<<": "<<x<<'\n'

#define fi first
#define se second

#define vi vector<int>
#define pb push_back
#define mp make_pair

#define pcnt __builtin_popcount

typedef long long ll;

const int inf = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

struct Edge{
    int to;
    int cost;
};
vector<vector<Edge> > G(110);
int d[110] = {};
int main(){
    int n;
    cin >> n;
    rep(i,n){
        int t,m;
        cin >> t >> m;
        rep(j,m){
            int a,b;
            cin >> a >> b;
            Edge ee;
            ee.to = a;ee.cost = b;
            G[t].push_back(ee);
        }
    }

    rep(i,n) d[i] = 900010000;
    d[0] = 0;
    while(true){
        bool update = false;
        rep(i,n){
            for(const auto& e: G[i]){
                if(d[i] + e.cost < d[e.to]){
                    d[e.to] = d[i]+e.cost;
                    update = true;
                }
            }
        }
        if(!update) break;
    }

    rep(i,n){
        cout << i << " " << d[i] << endl;
    }

    return 0;
}

C++: #include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;

struct edge { int from, to, cost; };
const int MAX_V=100;
const int INF=1e9;

vector<edge> es;
int d[MAX_V];
int n;

void shortest_path(int s){
  REP(i, n) d[i] = INF;
  d[s] = 0;
  while(true){
    bool update = false;
    for(edge e : es){
      if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
	d[e.to] = d[e.from] + e.cost;
	update = true;
      }
    }
    if(!update) break;
  }
}

int main(){
  cin>>n;
  REP(i,n){
    int u, k; cin>>u>>k;
    REP(j,k){
      edge e;
      e.from = u;
      cin>>e.to>>e.cost;
      es.push_back(e);
    }
  }
  shortest_path(0);
  REP(i,n){
    cout<<i<<" "<<d[i]<<endl;
  }
}

C++: #include <iostream>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <cstring>
#include <cmath>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)

#define debug(x) cerr<<#x<<": "<<x<<'\n'

#define fi first
#define se second

#define vi vector<int>
#define pb push_back
#define mp make_pair

#define pcnt __builtin_popcount

typedef long long ll;

const ll inf = 99900100100;
const int MOD = 998244353;
const double EPS = 1e-9;

vector<vector<pair<int,int> > > G(110);

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    rep(i,n){
      int u,k;
      cin >> u >> k;
      rep(j,k){
        int v,c;
        cin >> v >> c;
        G[u].push_back(mp(v,c));
        G[v].push_back(mp(u,c));
      }
    }
    ll d[110] = {};
    rep(i,110) d[i] = inf;
    d[0] = 0;
    while(true){
        bool update = false;
        rep(i,n){
          for(auto o : G[i]){
            if(d[o.fi] > d[i]+o.se){
                d[o.fi] = d[i]+o.se;
                update = true;
            }
          }
        }
        if(!update) break;
    }
    rep(i,n) cout << i << " " << d[i] << endl;
    return 0;
}