Go: package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

const (
	INFTY = 1 << 21
	NIL   = -1
)

const (
	WHITE = iota
	GRAY
	BLACK
)

type Graph [][]int

func (g *Graph) dikstra(n int) string {
	var (
		u, minv = 0, 0
	)

	d := make([]int, n)
	color := make([]int, n)

	for i := 0; i < n; i++ {
		d[i] = INFTY
		color[i] = WHITE
	}
	d[0] = 0
	color[0] = GRAY

	for {
		minv = INFTY
		u = -1
		for 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 v := 0; v < n; v++ {
			if color[v] != BLACK && (*g)[u][v] != INFTY {
				if d[v] > d[u]+(*g)[u][v] {
					d[v] = d[u] + (*g)[u][v]
					color[v] = GRAY
				}
			}
		}
	}

	var out bytes.Buffer
	for i := 0; i < n; i++ {
		out.WriteString(fmt.Sprintf("%d ", i))
		if d[i] == INFTY {
			out.WriteString(fmt.Sprintf("%d\n", -1))
			continue
		}
		out.WriteString(fmt.Sprintf("%d\n", d[i]))
	}

	return strings.TrimRight(out.String(), "\n")
}

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	g := make(Graph, n)
	for i := 0; i < n; i++ {
		g[i] = make([]int, n)
		for j := 0; j < n; j++ {
			g[i][j] = INFTY
		}
	}

	for i := 0; i < n; i++ {
		sc.Scan()
		u, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())

		for j := 0; j < k; j++ {
			sc.Scan()
			v, _ := strconv.Atoi(sc.Text())
			sc.Scan()
			c, _ := strconv.Atoi(sc.Text())

			g[u][v] = c
		}
	}

	return g.dikstra(n)
}

func main() {
	fmt.Println(answer(os.Stdin))
}

C++: #include<iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n,M[MAX][MAX];

void dijkstra()
{
  int minv;
  int d[MAX],color[MAX];

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

  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;
  for(int i=0;i<n;i++)
  {
    for(int j=0;j<n;j++)
    {
      M[i][j] = INFTY;
    }
  }

  int k,c,u,v;
  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<iostream>
#include<vector>
#include<queue>
#define INF 2e9
using namespace std;

void Dikstra(const vector<vector<pair<int, int> > >& G, vector<int>& d){
    d[0] = 0;
    priority_queue<pair<int, int> , vector<pair<int, int> >, greater<pair<int, int> > > PQ;
    PQ.push(make_pair(0, 0));
    vector<bool> is_black(d.size(), false);
    is_black[0] = true;
    while (!PQ.empty()) {
        int t = PQ.top().second;
        PQ.pop();
        is_black[t] = true;
        for (int i = 0; i < G[t].size(); i++) {
            int v = G[t][i].first;
            int w = G[t][i].second;
            if (!is_black[v] && d[t] + w < d[v]) {
                bool flag = false;
                d[v] = d[t] + w;
                PQ.push(make_pair(d[v], v));
            }
        }
    }

}

int main(){
    int n;
    cin >> n;
    vector<vector<pair<int, int> > > G(n);
    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[u].push_back(make_pair(v, c));
        }
    }
    vector<int> d(n, INF);
    Dikstra(G, d);
    for (int i = 0; i < n; i++) {
       cout << i << " " << d[i] << endl;
    }

    return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

const int INF = 1001001001;

int main(){
  int n;
  cin >> n;
  vector<vector<pair<int, int>>> gr(n, vector<pair<int, int>>());
  rep(i, n){
    int a;
    cin >> a;
    int k;
    cin >> k;
    rep(j, k){
      int v, c;
      cin >> v >> c;
      gr.at(i).push_back(make_pair(v, c));
    }
  }
  vector<int> d(n, INF);
  vector<bool> chk(n, false);
  d.at(0) = 0;
  chk.at(0) = true;
  int now = 0;
  rep(i, n-1){
    for(auto p : gr.at(now)){
      if(chk.at(p.first) == true) continue;
      d.at(p.first) = min(d.at(p.first), d.at(now) + p.second);
    }
    int mn = INF, nx = -1;
    rep(j, n){
      if(chk.at(j) == true) continue;
      if(mn > d.at(j)){
        mn = d.at(j);
        nx = j;
      }
    }
    if(nx == -1) break;
    chk.at(nx) = true;
    now = nx;
  }

  rep(i, n){
    cout << i << " " << d.at(i) << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define MAX_V 100
#define INF (1 << 21)

struct edge { int to, cost; };
typedef pair<int, int> P;

int V;
vector<edge> G[MAX_V];
int d[MAX_V];

// int cost[MAX_V][MAX_V];
// bool used[MAX_V];

int s = 0; // start

void dijkstra()
{
    priority_queue<P, vector<P>, greater<P> > que;
    for (int i = 0; i < V; i++) {
        d[i] = INF;
        // used[i] = false;
    }
    d[s] = 0;
    que.push(P(0, s));

    for (; !que.empty();) {
        P 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(P(d[e.to], e.to));
            }
        }
    }

    for (int u = 0; u < V; u++) {
        cout << u << " " << (d[u] == INF ? -1 : d[u]) << endl;
    }

}
int main()
{
    cin >> V;

    // for (int i = 0; i < V; i++) {
    //     for (int j = 0; j < V; j++) {
    //         cost[i][j] = INF;
    //     }
    // }

    for (int i = 0; i < V; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int v, c;
            cin >> v >> c;
            G[u].push_back({v, c});
            // cost[u][v] = c;
        }
    }

    dijkstra();

    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxx=110;
const int infinity=(1<<21);

int A[maxx][maxx];
int d[maxx];
bool flag[maxx];

int main (){
	int n,a,b,c,minv,mini;
	cin>>n;
	for(int i=0;i<maxx;i++){
		flag[i]=false;
		d[i]=infinity;
		for(int j=0;j<maxx;j++){
			A[i][j]=infinity;
		}
	}
	for(int i=0;i<n;i++){
		cin>>a>>b;
		for(int j=0;j<b;j++){
			cin>>c>>A[a][c];
		}
	}
	
	d[0]=0;
	while(1){
		minv=infinity,mini=-1;
		for(int i=0;i<n;i++){
			if(flag[i]==false && d[i]<minv){
				minv=d[i];
				mini=i;
			}
		}
		if(mini==-1 || minv==infinity) break;
		flag[mini]=true;
		for(int i =0;i<n;i++){
			if(A[mini][i]!=infinity && flag[i]==false && d[mini]+A[mini][i]<d[i]){
					d[i]=d[mini]+A[mini][i];
			}
		}
		
	}
	cout<<n<<endl;
	int nn=n;
	for(int i=0;i<nn;i++) cout<<i<<" "<<d[i]<<endl;
	
	return 0;

}