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>

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
const int INF = 1e9;

using namespace std;
int n;
int res = 0;
struct node {
    int id;
    int dist;
    bool searched;
};

node v[100];
int edge[100][100];

int main() {
    cin >> n;
    REP(i, n) {
        int u, k;
        cin >> u >> k;
        v[u].id = u;
        v[u].dist = INF;
        v[u].searched = false;
        REP(j, n) edge[i][j] = INF;
        REP(j, k){
            int to, cost;
            cin >> to >> cost;
            edge[i][to] = cost;
        }
    }
    v[0].dist = 0;
    int prev = 0;
    REP(i, n){
        int minimum = INF;
        REP(j, n){
            if(!v[j].searched && minimum >= v[j].dist){
                prev = j;
                minimum = v[j].dist;
            }
        }
        REP(j, n){
            if(!v[j].searched && edge[prev][j] != INF){
                v[j].dist = min(v[j].dist, v[prev].dist + edge[prev][j]);
            }
        }
        v[prev].searched = true;
    }
    REP(i, n) cout << i << " " << v[i].dist << endl;
    return 0;
}

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

#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
//int INF = (1<<21);

void dijkstra(void);

int n;
int M[MAX][MAX];

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

void dijkstra(){
  int minV;
  int d[MAX],color[MAX];
  int u,v;
  int i;
  for(i = 0; i < n; i++){
    d[i] = INFINITY;
    //d[i] = INF;
    color[i] = WHITE;
  }
  d[0] = 0;
  color[0] = GRAY;
  while(1){
    minV = INFINITY;
    //minV = INF;
    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 && M[u][v] != INFINITY){
      //if(color[v] != BLACK && M[u][v] != INF){
        if(d[v] > d[u] + M[u][v]){
          d[v] = d[u] + M[u][v];
          color[v] = GRAY;
        }
      }
    }
  }
  for(i = 0; i < n; i++){
    cout << i << " " << (d[i] == INFINITY ? -1 : d[i]) << endl;
    //cout << i << " " << (d[i] == INF ? -1 : d[i]) << endl;
  }
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <stack>
#include <cctype>
#include <cmath>

using namespace std;

/* typedef */

typedef long long ll;

/* constant */

const int INF = 1 << 30;
const int MAX = 100;
const int mod = 1000000007;
const double pi = 3.141592653589;

const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;

/* global variables */
vector< vector<int> > Adj(MAX, vector<int>(MAX, INF));
vector<int> color(MAX, WHITE);
vector<int> d(MAX, INF);
vector<int> p(MAX, -1);
int n;
int total_cost = 0;

/* function */
void prim();

/* main */
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][v] = c;
        }
    }

    prim();

    for (int i = 0; i < n; i++ ) {
        cout << i << ' ' << d[i] << '\n';
    }
   

}

void prim() {

    int u;
    int min_cost = INF;
    d[0] = 0;
    p[0] = -1;

    while (1) {

        u = -1;
        min_cost = INF;
        for (int i = 0; i < n; i++) {
            if (color[i] != BLACK && d[i] < min_cost) {
                u = i;
                min_cost = d[i];
            }
        }
        if (min_cost == INF) {
            break;
        }

        color[u] = BLACK;

        for (int v = 0; v < n; v++) {
            if (color[v] != BLACK && Adj[u][v] != INF) {
                if (d[u] + Adj[u][v] < d[v]) {
                    p[v] = u;
                    d[v] = d[u] + Adj[u][v];
                    color[v] = GRAY;
                }
            }
        }
    }

}

C++: #include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { -1, 0, 1, 0 };

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin >> n;

	vector<vector<pair<int, int>>> graph(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;
			graph[u].emplace_back(v, c);
		}
	}

	vector<int> dist(n, INF);
	dist[0] = 0;
	priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
	pq.emplace(0, 0);

	while (!pq.empty()) {
		pair<int, int> p = pq.top(); pq.pop();
		if (dist[p.first] < p.second) {
			continue;
		}

		for (auto e : graph[p.first]) {
			if (dist[e.first] > dist[p.first] + e.second) {
				dist[e.first] = dist[p.first] + e.second;
				pq.emplace(e.first, dist[e.first]);
			}
		}
	}

	for (int i = 0; i < n; i++) {
		cout << i << " " << dist[i] << endl;
	}
	return 0;
}