Go: package main

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

const (
	MAX_N      = 10000
	MAX_WEIGHT = 100000
)

type Edge struct {
	start  int
	end    int
	weight int
}

type ShortestInfo struct {
	edges    []Edge
	shortest int
}

func main() {
	doMain(os.Stdin)
}

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

	n, err := nextInt(sc)
	if err != nil {
		panic(err)
	}

	shortestList := make([]ShortestInfo, n)
	for i := 1; i < n; i++ {
		shortestList[i] = ShortestInfo{edges: []Edge{}, shortest: MAX_N*MAX_WEIGHT + 1}
	}

	adjacentMatrix, err := createAdjacentMatrix(n, sc)
	if err != nil {
		panic(err)
	}

	sssp([]int{0}, shortestList, adjacentMatrix)
	for _, v := range shortestList {
		fmt.Println(v.getEnd(), v.shortest)
	}
}

func (si ShortestInfo) getEnd() int {
	if len(si.edges) == 0 {
		return 0
	} else {
		return si.edges[len(si.edges)-1].end
	}
}

func createAdjacentMatrix(n int, sc *bufio.Scanner) ([][]int, error) {
	adjacentMatrix := make([][]int, n)
	for i := 0; i < n; i++ {
		id, err := nextInt(sc)
		if err != nil {
			return nil, err
		}
		adjacentMatrix[id] = make([]int, n)
		for j := 0; j < n; j++ {
			adjacentMatrix[id][j] = -1
		}
		vertexNum, err := nextInt(sc)
		if err != nil {
			return nil, err
		}
		for j := 0; j < vertexNum; j++ {
			v, err := nextInt(sc)
			if err != nil {
				return nil, err
			}
			c, err := nextInt(sc)
			if err != nil {
				return nil, err
			}
			adjacentMatrix[id][v] = c
		}
	}
	return adjacentMatrix, nil
}

func sssp(nodeStack []int, shortestList []ShortestInfo, adjacentMatrix [][]int) {
	for len(nodeStack) > 0 {
		currentNode := nodeStack[0]
		nodeStack = nodeStack[1:]
		currentShortest := getShortest(currentNode, shortestList)
		adjacents := findAdjacents(currentNode, adjacentMatrix)
		for i := 0; i < len(adjacents); i++ {
			adj := adjacents[i]
			if currentShortest.shortest+adj.weight < getShortest(adj.end, shortestList).shortest {
				setShortest(adj.end, adj, currentShortest, shortestList)
				nodeStack = append(nodeStack, adj.end)
			}
		}
	}
}

func getShortest(node int, shortestList []ShortestInfo) ShortestInfo {
	return shortestList[node]
}

func setShortest(node int, edge Edge, currentShortest ShortestInfo, shortestList []ShortestInfo) {
	newEdges := make([]Edge, len(currentShortest.edges)+1)
	for i := 0; i < len(newEdges)-1; i++ {
		newEdges[i] = currentShortest.edges[i]
	}
	newEdges[len(newEdges)-1] = edge
	shortestInfo := ShortestInfo{edges: newEdges, shortest: currentShortest.shortest + edge.weight}
	shortestList[node] = shortestInfo
}

func findAdjacents(currentNode int, adjacentMatrix [][]int) []Edge {
	adjacents := adjacentMatrix[currentNode]
	edges := []Edge{}
	for i, v := range adjacents {
		if v >= 0 {
			edges = append(edges, Edge{start: currentNode, end: i, weight: v})
		}
	}
	return edges
}

func nextInt(sc *bufio.Scanner) (int, error) {
	sc.Scan()
	return strconv.Atoi(sc.Text())
}

C++: #include <bits/stdc++.h>

using namespace std;
using ll =long long;

static const int inf = (1<<21);
static const int white = 0;
static const int gray =  1;
static const int black = 2;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//Write From this Line

int n;
vector<pair<int,int>> adj[10010]; // 重み付き有向グラフのリスト表現


void dijkstra(){
	priority_queue<pair<int, int> > p_que;
	int color[10010];
	int d[10010];
	rep(i, n){
		d[i] = inf;
		color[i] = white;
	}

	d[0] = 0;
	p_que.push(make_pair(0,0));
	color[0] = gray;

	while( !p_que.empty() ){
		pair<int, int> f = p_que.top(); p_que.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;
				p_que.push(make_pair(d[v] * (-1), v));
				color[v] = gray;
			}
		}
	}
	rep(i, n){
		cout << i << " " << (d[i] == inf ? -1 : d[i]) << endl;
	}
}

int main()
{
	cin >> n;
	rep(i,n){
		int u, k;
		cin >> u >> k;
		rep(j,k){
			int a, b;
			cin >> a >> b;
			adj[u].push_back(make_pair(a,b));
		}
	}
	dijkstra();
	return 0;
}

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

#define rep(i, n) REP(i, 0, n)
#define REP(i, k, n) for(auto i = k; i != n; i++)
#define rrep(i, n) RREP(i, n, 0)
#define RREP(i, n, k) for(auto i = n; i != k; i--)
#define ALL(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << " " << x << endl
#define in(x, data) (data).find(x) != (data).end()

typedef long long ll;
typedef pair<int, int> PRii;

class Node {
public:
    int dist, number;
    Node(int d, int n) {
        dist = d;
        number = n;
    }
};

bool operator < (const Node &l, const Node &r) {
    return l.dist < r.dist
    || (!(r.dist < l.dist) && l.number < r.number);
};

bool operator > (const Node &l, const Node &r) {
    return r < l;
};

class Edge {
public:
    int to, cost;
    Edge(int t, int c) {
        to = t;
        cost = c;
    }
};

int node_n;
vector<vector<Edge>> edge;
vector<int> d;

void cost_initializer(int n) {
    edge = vector<vector<Edge>>(n, vector<Edge>());
}

void dijkstra(int start_p) {
    d = vector<int>(node_n, INT_MAX); d[start_p] = 0;
    vector<int> prev = vector<int>(node_n);

    priority_queue<Node,vector<Node>,greater<Node>> Q;

    for(int i=0; i<node_n; i++) {
        Q.push(Node(d[i],i));
    }

    while(!Q.empty()) {
        Node u = Q.top(); Q.pop();
        if(u.dist > d[u.number]) continue;
        for(int i=0; i<edge[u.number].size(); i++) {
            int alt = d[u.number] + edge[u.number][i].cost;
            int v = edge[u.number][i].to;
            if(d[v] > alt) {
                d[v] = alt;
                prev[v] = u.number;
                Q.push(Node(d[v],v));
            }
        }
    }
}

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

    int n; cin >> n;
    node_n = n;
    cost_initializer(node_n);

    rep(i,n) {
        int u, k; cin >> u >> k;
        rep(j,k) {
            int v, c; cin >> v >> c;
            edge[u].push_back(Edge(v,c));
        }
    }

    dijkstra(0);
    rep(i,n) cout << i << " " << d[i] << endl;
    return 0;
}