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<stdio.h>
#define MAX 2001
#define NIL -1
#define B -2
#define W -1
#define G 0
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;

int d[MAX];
int p[MAX];
int color[MAX];
int n;
int u;
int k;
int c;
int v;
int M[MAX][MAX];
queue <int> Q;

void DIJKSTRA() {
	for (int i = 0; i < n; i++) {
	    d[i] = 9000000;
		p[i] = NIL;
		color[i] = W;
	}
	d[0] = 0;
	color[0] = B;
	int s = 0;
	Q.pop();
	int count = 0;
	while (!Q.empty()) {
		count++;
		for (int i = 0; i < n; i++) {
			if (M[s][i] != -1 && color[i] != B) {
				
				if (d[i] > d[s] + M[s][i]) {
					
					d[i] = d[s] + M[s][i];
					p[i] = s;
					color[i] = G;
					
					
				}
			}
		}
		int a = 0;
		int mini = MAX;
		for (int j = 0; j < n; j++) {
			
			if (color[j] == G) {
		
				if(mini>d[j]){
					a = j;
				}
				mini = min(mini, d[j]);
			}

		}
		s = a;
		color[a] = B;
		Q.pop();
		
	}
	
}
int main(){

	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			M[i][j] = -1;
		}
	}

	for (int i = 0; i < n; i++) {
		cin >> u; cin >> k;
		for (int j = 0; j < k; j++) {
			cin >> v >> c;
			M[u][v] = c;
			Q.push(i);
		}
	}

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

C++: #include <cstdio>

const int N = 100;
const int INF = 10000001;
int cost[N][N];
int minCost[N] = {0};
bool isDecide[N] = {false};

int getMinIndex(int n) {
        int minIndex = -1;
        int cost = INF;
        for (int i = 0; i < n; i++) {
                if (minCost[i] < cost && !isDecide[i]) {
                        cost = minCost[i];
                        minIndex = i;
                }
        }

        return minIndex;
}

int main() {
        for (int i = 0; i < N; i++) {
                for (int j = 0; j < N; j++) {
                        cost[i][j] = -1;
                }
        }
        for (int i = 1; i < N; i++) {
                minCost[i] = INF;
        }
        int n, u, k, v, c;

        scanf("%d", &n);
        for (int i = 0; i < n; i++) {
                scanf("%d %d", &u, &k);
                for (int j = 0; j < k; j++) {
                        scanf("%d %d", &v, &c);
                        cost[u][v] = c;
                }
        }
        while (true) {
                int from = getMinIndex(n);
                if (from < 0) {
                        break;
                }
                isDecide[from] = true;
                for (int to = 0; to < n; to++) {
                        if (cost[from][to] < 0 || isDecide[to]) {
                                continue;
                        }
                        int newCost = minCost[from] + cost[from][to];
                        if (newCost < minCost[to]) {
                                minCost[to] = newCost;
                        }
                }
        }
        for (int i = 0; i < n; i++) {
                printf("%d %d\n", i, minCost[i]);
        }

        return 0;
}

C++: #include <bits/stdc++.h>
#define REP(i, a, b) for(int i = (a); i < (b); i++)
#define RREP(i, a, b) for(int i = (a); i >= (b); i--)
#define pq priority_queue
#define P pair<int, int>
#define P2 pair<int, P>
#define P3 pair<int, P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF = 1e9, MOD = 1e9+7, around[] = {0, 1, 1, -1, -1, 0, -1, 1, 0, 0};
const int vx[] = {1, 0, -1, 0}, vy[] = {0, 1, 0, -1};
const ld PI = abs(acos(-1));
const int sqrtN = 512;
const int logN = 32;
const ll LINF=1e18;

template<typename T>
struct Dijkstra{
	struct edge{
		int to;
		T cost;
	};
	const T INF;
	vector<vector<edge>> g;
	vector<T> min_cost;
	
	Dijkstra(int n) : INF(numeric_limits<T>::max()){
		g.resize(n);
	}
	
	void add_edge(int from, int to, T cost){
		g[from].push_back(edge{to, cost});
	}
	
	vector<T> dijkstra(int s){
		min_cost.assign(g.size(), INF); min_cost[s] = 0;
		pq<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> qu;
		qu.push({0, s});
		
		while(!qu.empty()){
			auto p = qu.top(); qu.pop();
			
			for(auto e:g[p.second]){
				if(p.first + e.cost >= min_cost[e.to]) continue;
				min_cost[e.to] = p.first + e.cost;
				qu.push({min_cost[e.to], e.to});
			}
		}
		
		return min_cost;
	}
};


int main(){
	int n; cin >> n;
	Dijkstra<ll> dijk(n);
	for(int i = 0; i < n; i++){
		int k; cin >> k >> k;
		
		for(int j = 0; j < k; j++){
			int a, b; cin >> a >> b;
			dijk.add_edge(i, a, (ll)b);
			dijk.add_edge(a, i, (ll)b);
		}
	}
	
	vector<ll> min_cost = dijk.dijkstra(0);
	for(int i = 0; i < n; i++) cout << i << " " << min_cost[i] << endl;
	return 0;
}