Go: package main

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

const (
	MAX_N      = 100
	MAX_WEIGHT = 100000
)

type Edge struct {
	start  int
	end    int
	weight int
}

type ShortestInfo struct {
	edges    []Edge
	shortest int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	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{1}, shortestList, adjacentMatrix)
	for _, v := range shortestList {
		fmt.Printf("%d %d\n", v.getEnd()-1, v.shortest)
	}
}

func (si ShortestInfo) getEnd() int {
	if len(si.edges) == 0 {
		return 1
	} 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-1]
}

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-1] = shortestInfo
}

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

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

C++: #include <iostream>
#include <vector>
#include <queue>

using namespace std; 

int main(void) {
	int u,noe,nov;
	cin >> nov;
	vector< vector< pair<int,int> > > el(nov);
	for (int i = 0; i < nov; ++i) {
		cin >> u >> noe;
		el[u] = vector< pair<int,int> >(noe);
		for (int j = 0; j < noe; ++j) {
			cin >> el[u][j].first;
			cin >> el[u][j].second;
		}
	}

	vector<int> res(nov,(1 << 28));
	res[0] = 0;
	pair<int,int> now,next;
	priority_queue< pair<int,int> > q;
	q.push({0,0});
	while (!q.empty()) {
		now = q.top();
		q.pop();
		for (int i = 0; i < el[now.second].size(); ++i) {
			next = el[now.second][i];
			if (res[next.first] > now.first+next.second) {
				res[next.first] = now.first+next.second;
				q.push({res[next.first],next.first});
			}
		}
	}

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

	return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>

using namespace std;

int main() {

	int INF = 10000000;

	int n;
	scanf("%d", &n);

	vector<pair<int, int>> G[n];
	for (int i = 0; i < n; ++i) {
		int from;
		scanf("%d", &from);

		int v;
		scanf("%d", &v);

		for (int j = 0; j < v; ++j) {
			int to;
			int w;
			scanf("%d %d", &to, &w);
			G[from].push_back(make_pair(to, w));
		}
	}

	int C[n];
	for (int i = 0; i < n; ++i)
		C[i] = INF;

	int color[n];
	int WHITE = 0;
	int BLACK = 1;
	for (int i = 0; i < n; ++i)
		color[i] = WHITE;

	priority_queue<pair<int, int>> PQ;
	PQ.push(make_pair(0, 0));
	C[0] = 0;
	while (!PQ.empty()) {
		int u = PQ.top().second;
		PQ.pop();
		color[u] = BLACK;
		for (int i = 0; i < (int) G[u].size(); ++i) {
			auto c = G[u][i];
			if (color[c.first] != BLACK && c.second + C[u] < C[c.first]) {
				C[c.first] = c.second + C[u];
				PQ.push(make_pair(C[c.first] * -1, c.first));
			}
		}
	}

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

	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;

int main() {
    int n;
    cin >> n;

    int a[n][n];
    int done[n]; // -1: まだ ソレ以外: 確定距離
    for (int i = 0; i < n; ++i) {
        done[i] = -1;
        for (int j = 0; j < n; ++j) {
            a[i][j] = -1;
        }
    }
    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;
            a[i][v] = c;
        }
    }

    // デバッグ用
//     for (int i = 0; i < n; ++i) {
//         for (int j = 0; j < n; ++j) {
//             cout << i << " " << j << " " << a[i][j] << endl;
//         }
//     }

    // 最初は0が確定済みのノードとなる
    done[0] = 0;

    // 確定済みのノードから行ける、未到達の最小のノードを探す
    // その最小のノードは次の確定済みとする...
    // とりあえずデバッグがてら10回す (最終的にwhileにして条件で対応する)
    // 全てdoneになったら終了
    for (int r = 0; r < n-1; ++r) {
        int next_node = -1;
        int next_cost = 1000000;
        for (int i = 0; i < n; ++i) {
            if (done[i] == -1) {
                // 未確定であれば何もしない
                continue;
            }

            for (int j = 0; j < n; ++j) {
                // 到達済みは見ない
                if (done[j] != -1) {
                    continue;
                }

                // コストが-1なら到達できない
                if (a[i][j] == -1) {
                    continue;
                }

                // 行けるところのコスト (iまでの距離+そこからの距離) を探す
//                cout << "src:" << i << " dst:" << j << " cost:" << a[i][j] << " total:" << done[i] + a[i][j] << endl;

                // 今のnext_costよりもtotalcostが小さければ、次のノードにしたい
                if ((done[i] + a[i][j]) < next_cost) {
                    next_cost = done[i] + a[i][j];
                    next_node = j;
                }
            }
        }
//        cout << "iter:" << r << endl;
//        cout << "next_node:" << next_node << endl;
//        cout << "next_cost:" << next_cost << endl;
        done[next_node] = next_cost;
    }

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

    return 0;
}