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 "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>>> g(n);
	for (int i = 0; i < n; i++) {
		int k, v;
		cin >> k >> v;
		for (int j = 0; j < v; j++) {
			int u, c;
			cin >> u >> c;
			g[k].emplace_back(u, c);
		}
	}

	vector<int> dist(n, INF);
	dist[0] = 0;
	vector<bool> used(n);

	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();
		int v = p.second;

		if (dist[v] < p.first) {
			continue;
		}

		for (auto e : g[v]) {
			int to = e.first;
			int cost = e.second;
			if (dist[to] > dist[v] + cost) {
				dist[to] = dist[v] + cost;
				pq.emplace(dist[to], to);
			}
		}
	}

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

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

#define INF 1000000000
using namespace std;

struct edge {
    int from;
    int to;
    int w;
};
struct node {
    node() : id {-1}, d {INF}, ns {} {};
    node(int i, vector<edge>& vec) : id {i}, d {INF}, ns {vec} {};
    int id;
    int d;
    vector<edge> ns;
};

vector<int> dijkstra(node* graph, int n, int st){
    auto ds = vector<int>(n, INF);
    auto comp = [](node& x, node& y){return x.d < y.d;};
    priority_queue<node, vector<node>, decltype(comp)> que(comp);
    node start = graph[st];
    start.d = 0;
    que.push(start);
    while(que.size()){
        node n = que.top();
        que.pop();
        if(n.d < ds[n.id]){
            ds[n.id] = n.d;
            for(auto e : n.ns){
                node next_n = graph[e.to];
                next_n.d = n.d + e.w;
                que.push(next_n);
            }
        }
    }
    return ds;
}

int main(){
    cin.sync_with_stdio(false);
    cout.sync_with_stdio(false);
    int n;
    cin >> n;
    node graph[n];
    for(int i = 0; i < n; ++i){
        int id;
        int m;
        cin >> id >> m;
        auto vec = vector<edge>(m);
        int v, c;
        for(int j = 0; j < m; ++j){
            cin >> v >> c;
            vec[j] = edge {id, v, c};
        }
        graph[id] = node(id, vec);
    }
    auto ds = dijkstra(graph, n, 0);
    for(int i = 0; i < n; ++i){
        cout << i << ' ' << ds[i] << endl;
    }
}

C++: #define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>

using namespace std;

static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
static const int NIL = -1;
static const int MAX = 100;
static const int INFTY = 10000000;


int colors[MAX] = { WHITE };	//各頂点の訪問状態
int graph[MAX][MAX] = { INFTY };
int d[MAX] = { INFTY };		//原点からの各頂点の距離
int p[MAX] = { NIL };		//親頂点

void dijkstra(int n) {

    d[0] = 0;
    colors[0] = WHITE;

    while (true) {

	int mincost = INFTY;
	int u;

	for (int i = 0; i < n; i++) {
	    //まだコストが確定しておらず、かつ現時点で仮コストが出ているもの
	    if (colors[i] != BLACK&&d[i] != INFTY) {

		//より小さいコストの原点からの距離があったら
		if (d[i] < mincost) {
		    mincost = d[i];
		    u = i;
		}
	    }
	}

	if (mincost == INFTY) {
	    break;
	}

	colors[u] = BLACK;

	//確定した頂点uからの近隣探索
	for (int i = 0; i < n; i++) {
	    
	    //まだ確定しておらずvから辺があれば
	    if (colors[i] != BLACK&&graph[u][i] != INFTY) {


		//現時点でiに行くコストより
		//頂点uを経由した方がコストが小さかったら
		if (d[u]+graph[u][i] < d[i]) {
		    d[i] = d[u] + graph[u][i];
		    p[i] = u;
		}

	    }

	}

    }
}

int main() {

    //cin.tie(0);
    //ios::sync_with_stdio(false);
    
    int n; scanf("%d", &n);
    int u; //頂点
    int k; //vからの辺の数
    int v; //uにつながる頂点v
    int c; //コスト

    //グラフ初期化
    for (int i = 0; i < n; i++) {
	for (int j = 0; j < n; j++) {
	    graph[i][j] = INFTY;
	}
    }
    
    //距離d初期化
    for(int i = 0; i < n; i++) {
	d[i] = INFTY;
    }

    //グラフ読み込み
    for (int i = 0; i < n; i++) {
	scanf("%d", &u);
	scanf("%d", &k);
	for (int j = 0; j < k; j++) {
	    scanf("%d", &v);
	    scanf("%d", &c);
	    graph[u][v] = c;
	}
    }


    //ダイクストラ法
    dijkstra(n);

    //表示
    for (int i = 0; i < n; i++) {
	printf("%d %d\n", i, d[i]);
    }

    return 0;

}