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>
#define rep(i,N) for(int i = 0; i<(int)(N); i++)
#define REP(i,k,N) for(int i = k; i<(int)(N); i++)
#define INF 100000+1
using namespace std;
const int MAX_N = 10000010;
bool d[MAX_N];
int main(){
        int n;
        cin >> n;
        int d[100][100];
        rep(i,100) rep(j,100) d[i][j]=INF;
        int u,k,v,c;
        rep(i,n){
                cin >> u >>k;
                rep(j,k){
                        cin >> v >> c;
                        d[u][v] = c;
                }
        }

        int l[n];
        rep(i,n) l[i]=INF;
        l[0]=0;
        bool update = true;
        while(update) {
                update  = false;
                rep(from,n) rep(to,n){
                        if(l[to] > l[from]+d[from][to]) {
                                update = true;
                                l[to] = l[from]+d[from][to];
                        }
                }
        }
        rep(i,n){
                cout << i << " " << l[i] << endl;
        }

        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;

}

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; i++ ){
            cin >> v >> c;
            M[u][v] = c;
        }
    }
    
    dijkstra();
    
    return 0;
}

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

int n;
vector<pair<int, int>> adj[100];
int *d;

void dijkstra() {
    priority_queue<pair<int, int>> PQ;
    int d[n], color[n];

    for (int i = 0; i < n; i++) {
        d[i] = INFTY;
        color[n] = WHITE;
    }
    d[0] = 0;
    PQ.push(make_pair(0, 0));

    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[u] + adj[u][j].second < d[v]) {
                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++) {
        printf("%d %d\n", i, d[i]);
    }
}

int main() {
    cin >> 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;
            adj[u].push_back(make_pair(v, c));
        }
    }

    dijkstra();

    return 0;
}

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<bits/stdc++.h>
#define REP(i,n) for(long long i=0;i<n;++i)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define F first
#define S second
using namespace std;

typedef pair< int,int > point;
vector< point > graph[101];
vector< int > v(101);
int n;
const int INF=1<<30;

void dijkstra(int s){
    priority_queue< point,vector< point >,greater< point > >pq;
    pq.push({0,s});
    fill(v.begin(),v.end(),INF);
    v[s]=0;
    while(!pq.empty()){
        point p=pq.top();
        pq.pop();
        REP(i,graph[p.S].size()){
            int nex=graph[p.S][i].S;
            int cost=p.F+graph[p.S][i].F;
            if(v[nex]>cost){
                v[nex]=cost;
                pq.push({cost,nex});
            }
        }
    }
}

int main(){
    scanf("%d",&n);
    int u,k,to,c;
    REP(i,n){
        scanf("%d%d",&u,&k);
        REP(j,k){
            scanf("%d%d",&to,&c);
            graph[u].push_back({c,to});
        }
    }
    dijkstra(0);
    REP(i,n){
        printf("%d ",i);
        printf("%d\n",v[i]);
    }
    return 0;
}