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>
#define MAX 100
#define MAXNUM 10000001
using namespace std;
int n, minv, M[MAX][MAX];
int w[MAX], color[MAX] = {};

void dijkstra() {
	for (int i = 0; i < n; i++) {
		w[i] = MAXNUM;
	}
	w[0] = 0;
	color[0] = 1;
	while (1) {
		minv = MAXNUM;
		int u = -1;
		for (int i = 0; i < n; i++) {
			if (w[i] < minv && color[i] != 2) {
				u = i;
				minv = w[i];
			}
		}
		if (u == -1) break;
		color[u] = 2;
		for (int i = 0; i < n; i++) {
			if (color[i] != 2 && M[u][i] != MAXNUM) {
				if (w[i] > w[u] + M[u][i]) {
					w[i] = w[u] + M[u][i];
					color[i] = 1;
				}
			}
		}
	}
}

int main() {
	int u, k, v, c;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			M[i][j] = MAXNUM;
		}
	}
	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			cin >> v >> c;
			M[u][v] = c;
		}
	}
	dijkstra();
	for (int i = 0; i < n; i++) {
		cout << i << " ";
		if (w[i] != MAXNUM) {
			cout << w[i] << endl;
		}
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
static const int MAX=100;
static const int INFTY=1000000000;
static const int WHITE=-1;
static const int BLACK=1;

int A[MAX][MAX],dk[MAX],p[MAX];

void SSSP(int n){
    int C[n];
    for(int i=0;i<n;i++){
        C[i]=WHITE;
        dk[i]=INFTY;
    }
    dk[0]=0;
    while(true){
        int u=-1;int minv=INFTY;
        for(int i=0;i<n;i++){
            if(C[i]==WHITE&&minv>dk[i]){
                minv=dk[i];
                u=i;
            }
        }
        if(u==-1)break;
        C[u]=BLACK;
        for(int i=0;i<n;i++){
            if(C[i]==WHITE&&A[u][i]!=INFTY){
                if(dk[i]>dk[u]+A[u][i]){
                    dk[i]=dk[u]+A[u][i];
                }
            }
        }
    }
}

int main(){
    int n,v,k,u,d;
    cin>>n;
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)A[i][j]=INFTY;

    for(int i=0;i<n;i++){
        scanf("%d %d",&v,&k);
        for(int j=0;j<k;j++){
            scanf("%d %d",&u,&d);
            A[v][u]=d;
        }
    }
    SSSP(n);
    for(int i=0;i<n;i++){
        printf("%d %d\n",i,dk[i]);
    }

}

C++: #include <cstdio>
#include <map>
using namespace std;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;
map<int, int> *M;
int *d;

void dijkstra() {
    int u, minv;
    int d[n], color[n];

    for (int i = 0; i < n; i++) {
        d[i] = INFTY;
        color[n] = WHITE;
    }
    d[0] = 0;

    while (1) {
        u = -1;
        minv = INFTY;
        for (int i = 0; i < n; i++) {
            if (color[i] != BLACK && d[i] < minv) {
                u = i;
                minv = d[i];
            }
        }

        if (u == -1) { break; }

        color[u] = BLACK;
        for (map<int, int>::iterator it = M[u].begin(); it != M[u].end(); it++) {
            if (color[it->first] != BLACK) {
                if (d[u] + it->second < d[it->first]) {
                    d[it->first] = d[u] + it->second;
                    color[it->first] = GRAY;
                }
            }
        }
    }
    
    for (int i = 0; i < n; i++) {
        printf("%d %d\n", i, d[i]);
    }
}

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

    M = new map<int, int>[n];

    for (int i = 0; i < n; i++) {
        int u, k;
        scanf("%d %d", &u, &k);
        for (int j = 0; j < k; j++) {
            int v, c;
            scanf("%d %d", &v, &c);
            M[u][v] = c;
        }
    }

    dijkstra();

    return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <queue>
#include <iomanip>
#include <algorithm>
#include <stack>
#include <cmath>
using namespace std;

#define INF 1e18
#define int long long
static const int MAX = 110;
static const int NOTFIXED = 0;
static const int FIXED = 1;

int n, m[MAX][MAX];

void dijkstra() {
    int d[n], status[n];
    for(int i = 0; i < n; i++) {
        d[i] = INF;
        status[i] = NOTFIXED;
    }
    d[0] = 0;
    status[0] = NOTFIXED;

    while(true) {
        int u = -1;
        int minv = INF;
        for(int i = 0; i < n; i++) {
            if(minv > d[i] && status[i] != FIXED) {
                u = i;
                minv = d[i];
            }
        }

        if(u == -1) break;
        status[u] = FIXED;
        for(int v = 0; v < n; v++) {
            if(m[u][v] != INF && status[v] != FIXED) {
                if(d[v] > d[u] + m[u][v]) {
                    d[v] = d[u] + m[u][v];
                    status[v] = NOTFIXED;
                }
            }
        }
    }

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

signed main() {
    cin >> n;

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            m[i][j] = INF;
        }
    }

    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;
            m[u][v] = c;
        }
    }

    dijkstra();

    return 0;
}