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>
#include<algorithm>
#include<vector>
#define MAX 101
#define INF 1000001
using namespace std;

int n, isSelected[MAX], dist[MAX];
vector<pair<int, int>> ver[MAX];

void initDijkstra(void);
void dijkstra(void);
bool doesFinished(void);

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

	initDijkstra();

	while (!doesFinished())dijkstra();

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

	return 0;
}

void initDijkstra(void) {

	dist[0] = 0;
	isSelected[0] = 1;
	for (int i = 1; i < n; i++)dist[i] = INF;

	vector<pair<int, int>>::iterator itv;

	for (itv = ver[0].begin(); itv != ver[0].end(); itv++) {
		dist[itv->first] = itv->second;
	}

}

void dijkstra(void) {
	int i, minu, mindist = INF;
	vector<pair<int, int>>::iterator itv;

	for (i = 0; i < n; i++) {
		if (isSelected[i] == 0)continue;
		for (itv = ver[i].begin(); itv != ver[i].end(); itv++){
			if (isSelected[itv->first] == 1)continue;
			if (itv->second < mindist) {
				mindist = itv->second;
				minu = itv->first;
			}
		}
	}
	isSelected[minu] = 1;
	//dist[minu] = dist[minp] + mindist;
	for (itv = ver[minu].begin(); itv != ver[minu].end(); itv++) {
		if (isSelected[itv->first] == 1)continue;
		dist[itv->first] = min(dist[minu] + itv->second, dist[itv->first]);
	}
}

bool doesFinished(void) {
	for (int i = 0; i < n; i++) {
		if (isSelected[i] == 0)return false;
	}
	return true;
}

C++: #include <iostream>
#include <vector>
#include <queue>
using namespace std;
#define INF 1e9
typedef pair<int, int> pi;
int graph[200][200];
int used[200];
int dist[200];
// first:weight, second:key
priority_queue<pi, vector<pi>, greater<pi>> pqueue;

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    dist[i] = INF;
    for (int j = 0; j < n; j++) {
      graph[i][j] = -1;
    }
  }
  for (int i = 0; i < n; i++) {
    int u, k;
    cin >> u >> k;
    int v, c;
    for (int j = 0; j < k; j++) {
      cin >> v;
      cin >> graph[u][v]; 
    }
  }
  
  pqueue.push(make_pair(0,0));
  dist[0] = 0;
  for (int i = 0; i < n; i++) {
    pi p = pqueue.top();
    pqueue.pop();
    int key = p.second;
    if (used[key] == 1) {
      i--;
      continue;
    }
    dist[key] = min(p.first, dist[key]);
    used[key] = 1;
    for (int j = 0; j < n; j++) {
      if (graph[key][j] != -1 && used[j] != 1) {
        int d = graph[key][j] + dist[key];
        pqueue.push(make_pair(d, j));
      }
    }
  }

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

C++: // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_12_A
// Graph II - Single Source Shortest Path I
// TODO: REVIEW

#define SUBMIT
//#define DEBUG

#include <utility>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <limits>
#include <numeric>
#include <functional>
#include <set>
#include <cmath>
#include <cstring>
#include <climits>
#include <memory>

using namespace std;
using ui64 = unsigned long long;
using i64 = long long;

enum class color_type {
    white,
    gray,
    black
};

const int INF = INT_MAX >> 1;
const ui64 MAX_N = 100;
int weight[MAX_N][MAX_N];
int n;

int dijkstra() {
    int d[MAX_N];
    color_type color[MAX_N];

    for (int i = 0; i < n; ++i) {
        d[i] = INF;
        color[i] = color_type::white;
    }

    d[0] = 0;
    color[0] = color_type::gray;
    while (true) {
        int u = -1, min_v = INF;
        for (int i = 0; i < n; ++i) {
            if(d[i] < min_v && color[i] != color_type::black) {
                u = i;
                min_v = d[i];
            }
        }

        if (u == -1) break;

        color[u] = color_type::black;
        for (int v = 0; v < n; ++v) {
            if (color[v] != color_type::black && weight[u][v] != INF) {
                if (d[u] + weight[u][v] < d[v]) {
                    d[v] = d[u] + weight[u][v];
                    color[v] = color_type::gray;
                }
            }
        }
    }

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

int main() {
#ifdef SUBMIT
    auto& stream = cin;
#else
    string program_input_str = R"(5
0 3 2 3 3 1 1 2
1 2 0 2 3 4
2 3 0 3 3 1 4 1
3 4 2 1 0 1 1 4 4 3
4 2 2 1 3 3
)";
    stringstream stream(program_input_str);
#endif

    stream >> n;
    for (int y = 0; y < n; ++y) {
        for (int x = 0; x < n; ++x) {
            weight[y][x] = INF;
        }
    }

    int u, v, c, degree;
    for (int i = 0; i < n; ++i) {
        stream >> u >> degree;
        for (int d = 0; d < degree; ++d) {
            stream >> v >> c;
            weight[u][v] = c;
        }
    }

#ifdef DEBUG
    for (int y = 0; y < n; ++y) {
        for (int x = 0; x < n; ++x) {
            cout << weight[y][x] << " ";
        }
        cout << endl;
    }
#endif

    dijkstra();
    return 0;
}