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<iostream>
#include<cstdio>
#define INF 1<<30
#define FinishFunction return 0
#define MAX 1000000
using namespace std;
  
  
struct edge {
  int from,to,cost,k;
};
  
edge es[MAX];
  
  
  
int main(){
  int n,u,k,E,c,v;
  E = 0;
  scanf("%d",&n);
  
  for(int i=0;i<n;i++){
    scanf("%d %d",&u,&k);
     
    for(int j=0;j<k;j++){
      scanf("%d %d",&v,&c);
      es[E].from = u;
      es[E].to = v;
      es[E++].cost = c;
    }
  }
  
    
  int d[MAX];
  for(int i=0;i<n;i++)d[i] = INF;
  d[0] = 0;
  while(true){
    bool update = false;
    for(int i=0;i<E;i++){
      edge e = es[i];
      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;
  
  
  }
  
  for(int i=0;i<n;i++)cout << i << " " << d[i] << endl;
  
  FinishFunction;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define INF 1<<29
#define MAXV 100

int V;      //????????°
int cost[MAXV+10][MAXV+10];

vector<int> dijkstra(int s){
    vector<int> d(V,INF);
    bool used[MAXV+10];
    for(int i=0;i<MAXV+10;i++) used[i]=false;

    d[s]=0;
    while(true){
        //??????????????????????????????????????§s??????????????¢???????°?????????????v??¨??????
        int v=-1;
        for(int u=0;u<V;u++){
            if(!used[u] and (v==-1 or d[u]<d[v])) v=u;
        }

        if(v==-1) break;
        
        used[v]=true;
        for(int u=0;u<V;u++){
            d[u] = min(d[u],d[v]+cost[v][u]);
        }
    }
    return d;
}

int main(){
    // initialize
    for(int i=0;i<MAXV+10;i++) for(int j=0;j<MAXV+10;j++) cost[i][j]=INF;

    cin >> V;
    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;
            cost[i][v]=c;
            cost[v][i]=c;
        }
    }

    vector<int> dis = dijkstra(0);
    for(int i=0;i<dis.size();i++){
        printf("%d %d\n",i,dis[i]);
    }
}

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

int n;
vector<pair<int,int> > adj[MAX];

void dijkstra(){
  priority_queue<pair<int,int> > PQ;
  int color[MAX];
  int d[MAX];
  for(int i=0;i<n;i++){
    d[i] = INFTY;
    color[i] = WHITE;
  }

  d[0] = 0;
  PQ.push(make_pair(0,0));
  color[0] = GRAY;

  while(!PQ.empty()){
    pair<int,int> f = PQ.top();PQ.pop();
    int u = f.second;
    color[u] = BLACK;

    if(d[u] < f.first*(-1)) continue;

    for(int j=0;j<adj[u].size();j++){
      int v = adj[u][j].first;
      if(color[v] == BLACK) continue;
      if(d[v] > d[u] + adj[u][j].second){
	d[v] = d[u] +adj[u][j].second;
	PQ.push(make_pair(d[v]*(-1),v));
	color[v] = GRAY;
      }
    }
  }

  for(int i=0;i<n;i++){
    cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
  }
}

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

  cin >> n;
  for(int i=0;i<n;i++){
    cin >> u >> k;
    for(int j=0;j<k;j++){
      cin >>v >> c;
      adj[u].push_back(make_pair(v,c));
    }
  }

  dijkstra();

  return 0;
}

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] = INFTY;
  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 < n ; j++){
      cin >> v >> c;
      M[u][v] = c;
    }
  }

  dijkstra();

  return 0;
}

C++: #include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##_max = (b); i < i##_max; ++i)
#define RFOR(i, a, b) for (int i = (b)-1, i##_min = (a); i >= i##_min; --i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
using vi = vector<int>;
using vd = vector<double>;
using i64 = int64_t;

constexpr int INF = 1 << 30;
constexpr int MOD = 1000000007;

template <typename T>
void print(vector<T> &v) {
  REP(i, v.size()) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
}

void dijkstra(vector<vi> &M) {
  auto n = M.size();
  vi d(n, INF);
  vector<bool> visited(n, false);
  d[0] = 0;
  while (true) {
    auto minv = INF;
    auto u = -1;
    REP(i, n) {
      if (!visited[i] && d[i] < minv) {
        minv = d[i];
        u = i;
      }
    }
    if (u == -1) break;
    visited[u] = true;
    REP(i, n) {
      if (!visited[i]) {
        d[i] = min(d[i], d[u] + M[u][i]);
      }
    }
  }
  REP(i, n) cout << i << " " << (d[i] == INF ? -1 : d[i]) << endl;
}

int main() {
  int n;
  cin >> n;
  vector<vi> M(n, vi(n, INF));
  int k, c, u, v;
  REP(i, n) {
    cin >> u >> k;
    REP(j, k) {
      cin >> v >> c;
      M[u][v] = c;
    }
  }
  dijkstra(M);
}