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;

#define rep(i, n) REP(i, 0, n)
#define REP(i,k,n) for(int i = k; i < n; i++)
#define mmax(start, end) *max_element(start, end)
#define mmin(start, end) *min_element(start, end)
#define argmax max_element
#define argmin min_element
#define push push_back
#define pop pop_back
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef string str;

int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

template<class T = ll> T in() {
    T _in;
    cin >> _in;
    return _in;
}

#define EMAX 10000000

int cost[101][101];

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

    ll n=in();
    ll d[101];

    rep(i, n) {
        rep(j, n) {
            cost[i][j] = EMAX;
        }
        d[i] = EMAX;
    }

    rep(i, n) {
        int u=in<int>(), k=in<int>();
        rep(j, k) {
            int v=in<int>(), c=in<int>();
            cost[u][v] = c;
        }
    }

    // ノード0からの距離を調べる
    d[0] = 0;
    bool flag = true;
    while(flag) {
        flag=false;
        // 移動する方法のある全ノードからの，次のノードへの移動コストを考える
        rep(i, n) {
            if(d[i] != EMAX) {
                rep(j, n) {
                    if(i == j)
                        continue;
                    int next_c = d[i] + cost[i][j];

                    // 更新できる場合更新
                    if(d[j] > next_c) {
                        d[j] = next_c;
                        flag=true;
                    }
                }
            }
        }
    }

    rep(i, n) {
        cout << i << " " << d[i] << endl;
        // rep(j, n) {
        //     cout << cost[i][j] << " ";
        // }
        // cout << endl;
    }
    
    return 0;
}

C++: #include<iostream>
#include<vector>
#define N 101
using namespace std;
int n;
vector<int> D(N,1<<30);
//bool visited[N];
vector<bool> visited(N,0);
vector<int> pre(N,0);
vector<vector<int>> M(N,vector<int>(N,0));
//int M[N][N];

void dijkstra(){
    D[0]=0;
    pre[0]=-1;

    while(1){
        int minD=1<<30;
        int u=-1;
        for(int i=0;i<n;i++){
            if(visited[i]) continue;
            if(D[i]<minD){
                u=i;
                minD=D[i];
            }
        }
        if(u==-1) break;

        visited[u]=1;
        for(int i=0;i<n;i++){
            if(visited[i]) continue;
            if(M[u][i]>0 && D[i]>D[u]+M[u][i]){
                D[i]=D[u]+M[u][i];
                pre[i]=u;
            }
        }

    }
}

void init(){
    cin>>n;
    int u,k,c,v;
    for(int i=0;i<n;i++){
        /*for(int j=0;j<n;j++){
            M[i][j]=0;
        }*/
        visited[i]=false;
        cin>>u>>k;
        for(int j=0;j<k;j++){
            cin>>v>>c;
            M[u][v]=c;
        }
    }
}

int main(){
    init();
    /*for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cout<<M[i][j]<<' ';
        }
        cout<<endl;
    }*/
    dijkstra();
    for(int i=0;i<n;i++){
        cout<<i<<' '<<D[i]<<endl;
    }
    return 0;
}

/*
5
0 3 2 3 3 1 1 2
1 2 0 2 3 4
2 3 0 3 3 1 4 1
3 4 2 1 0 1 1 4 4 3
4 2 2 1 3 3
*/

C++: #include<stdio.h>
using namespace std;
const int maxn=1<<21;
int n;
int a[105][105];
void dan()
{
    int minx;
    int d[105],color[105];
    for(int i=0;i<n;i++)
    {
        d[i]=maxn;
        color[i]=0;
    }
    d[0]=0;
    while(1)
    {
        minx=maxn;
        int u=-1;
        for(int i=0;i<n;i++)
        {
            if(d[i]<minx&&color[i]!=1)
            {
                minx=d[i];
                u=i;
            }
        }
        if(u==-1) break;
        color[u]=1;
        for(int i=0;i<n;i++)
        {
            if(color[i]==1||a[u][i]==maxn) continue;
            if(d[i]>d[u]+a[u][i])
            {
                d[i]=d[u]+a[u][i];

            }
        }
    }
    for(int i=0;i<n;i++)
    {
        printf("%d ",i);
        printf("%d\n",(d[i]==maxn)?-1:d[i]);
    }
}
int main()
{
    scanf("%d",&n);
    for(int i=0;i<105;i++)
    {
        for(int j=0;j<105;j++)
        {
            a[i][j]=maxn;
        }
    }
    int k,c,u,v;
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&k,&c);
        for(int j=0;j<c;j++)
        {
            scanf("%d%d",&u,&v);
            a[k][u]=v;
        }
    }
    dan();
    return 0;
}