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 <stdio.h>
int a[10000][10000];
int d[10000];
int p[10000];
int q[10000];
int main(){
    int n, i, j, t, u, v,c=0;
    scanf("%d", &n);
    for(i = 0; i < n; i++)
        for(j = 0; j < n; j++){
            a[i][j]=1000000000;
            if(i == j) a[i][j] = 0;
        }
    for(i = 0; i < n; i++) {
        scanf("%d", &j);
        scanf("%d", &c);
        for(j = 0; j < c; j++) {
            scanf("%d %d", &t, &u);
            a[i][t] = u;
        }
        d[i] = 1e9;
        q[i] = 0;
    }
    d[0] = 0;
    c = 0;
    while(c != n) {
        t = 0;
        j = 1000000001;
        for(i = 0; i < n;i++) {
            if(!q[i]&&d[i] < j) {
                t = i;
                j = d[i];
            }
        }
        q[t] = 1;c++;
        for(i = 0; i < n; i++) {
            if(a[t][i] != 1000000000) {
                if(d[i] > d[t] + a[t][i]) {
                    d[i] =  d[t] + a[t][i];
                }
            }
        }
    }
    for(i = 0; i < n; i++) {
        printf("%d %d\n", i, d[i]);
    }
    return 0;
}

C++: #include <iostream>
using ll = long long;
using namespace std;
/* initialize */
int n, u, k, v, c, A[100][100];

void dijkstra(){
    int c[100], d[100], p[100];
    for (int i = 0; i < n; ++i) { c[i] = 0;  d[i] = 100000000;}
    d[0] = 0;
    p[0] = -1;
    int minc;
    while(true){
        minc = INT32_MAX;
        int u = -1;
        for (int i = 0; i < n; ++i) {
            if (c[i] != 2 && d[i] < minc){
                minc = d[i];
                u = i;
            }
        }
        if(u == -1) break;

        c[u] = 2;

        for (int v = 0; v < n; ++v) {
            if (c[v] != 2 && A[u][v] != 100000000){
                if(d[u] + A[u][v] < d[v]){
                    d[v] = d[u] + A[u][v];
                    p[v] = u;
                    c[v] = 1;
                }
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        cout << i << " " << (d[i] == 100000000 ? -1 : d[i]) << "\n";
    }
};
/* main */
int main() {
    cin >> n;
    for (int l = 0; l < n; ++l) {
        for (int i = 0; i < n; ++i) {
            A[l][i] = 100000000;
        }
    }
    for (int i = 0; i < n; ++i) {
        scanf("%d %d", &u, &k);
        for (int j = 0; j < k; ++j) {
            scanf("%d %d", &v, &c);
            A[u][v] = c;
        }
    }
    dijkstra();
    return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
#define MAX_N 100
#define INF 1e9

int cost[MAX_N][MAX_N];
int d[MAX_N];
bool used[MAX_N];
int n, u, k, c, v;

void dijkstra(int s){
  fill(d, d + n, INF);
  fill(used, used + n, false);
  d[s] = 0;

  while(true){
    int v = -1;

    for(int u = 0; u < n; u++){
      if(!used[u] && (v == -1 || d[u] < d[v])) v = u;
    }

    if(v == -1) break;
    used[v] = true;

    for(int u = 0; u < n; u++){
      d[u] = min(d[u], d[v] + cost[v][u]);
    }
  }
}

int main(void){
  cin >> n;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      cost[i][j] = INF;
    }
  }
  for(int i = 0; i < n; i++){
    cin >> u >> k;
    for(int j = 0; j < k; j++){
      cin >> v >> c;
      cost[u][v] = c;
    }
  }
  dijkstra(0);
  for(int i = 0; i < n; i++){
    cout << i << " " << d[i] << endl;
  }
  return 0;
}