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 {{{
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <tuple>
#include <utility>
#include <random>
#include <limits>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>
// }}}

using namespace std;

// macros {{{
template<typename T, size_t N>
constexpr size_t NELEMS(T (&)[N]) { return N; }

template<typename InputIt>
void PRINT_RANGE(InputIt first, InputIt last)
{
    for(; first != last; ++first)
        cout << *first << (first==last ? "" : " ");
    cout << "\n";
}

template<typename T>
void PRINT_MATRIX(T mat, size_t nr, size_t nc)
{
    for(size_t r = 0; r < nr; ++r) {
        for(size_t c = 0; c < nc; ++c) {
            cout << mat[r][c] << (c==nc-1 ? "" : " ");
        }
        cout << "\n";
    }
}

#define FOR(i, start, end) for(int i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)
// }}}

// types {{{
using ll  = long long;
using ull = unsigned long long;
// }}}

constexpr int INF = numeric_limits<int>::max();

int N;
int G[100][100];

void solve()
{
    vector<int> cost(N);
    deque<bool> done(N);

    fill(begin(cost), end(cost), INF);
    cost[0] = 0;

    for(;;) {
        int mincost = INF;
        int minv    = -1;

        REP(v, N) {
            if(done[v]) continue;
            if(cost[v] < mincost) {
                mincost = cost[v];
                minv    = v;
            }
        }

        if(minv == -1) break;

        done[minv] = true;

        REP(v, N) {
            if(done[v]) continue;
            if(G[minv][v] == -1) continue;
            int cost_new = cost[minv] + G[minv][v];
            if(cost_new < cost[v]) {
                cost[v] = cost_new;
            }
        }
    }

    REP(v, N) {
        cout << v << " " << cost[v] << "\n";
    }
}

int main()
{
    cin >> N;
    REP(from, N) {
        REP(to, N) {
            G[from][to] = -1;
        }
    }

    REP(_, N) {
        int from, k;
        cin >> from >> k;
        REP(_, k) {
            int cost, to;
            cin >> to >> cost;
            G[from][to] = cost;
        }
    }

    solve();

    return 0;
}

C++: #include <iostream>
using namespace std;

#define M 100
#define WHITE 1
#define BLACK 2
#define GRAY 3
#define INFTY (1<<21)

int n,A[M][M];

void dic(){
  int d[M],p[M],min,color[M],u;

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

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

    color[u] = BLACK;

    for(int i = 0;i < n;i++){
      if(color[i] != BLACK && A[u][i] != INFTY){
	if(d[u] + A[u][i] < d[i]){
	  d[i] = d[u] + A[u][i];
	  p[i] = u;
	  color[i] = GRAY;
	}
      }
    }
  }
  for(int i = 0;i < n;i++){
    cout << i << " ";
    if(d[i] != INFTY) cout << d[i];
    else cout << -1;
    cout << endl;
  }
}

int main(){
  int s,t,u,v;
    
  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++){
    cin >> s >> t;
    for(int j = 0;j < t;j++){
      cin >> u >> v;
      A[s][u] = v;
    }
  }

  dic();

  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

void dijkstra(void);

int n;
int M[MAX][MAX];

int main(){
  int i,j;
  int k,c,u,v;
  cin >> n;
  for( i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      M[i][j] = INFINITY;
    }
  }
  for(i = 0; i < n; i++){
    cin >> u;
    cin >> k;
    for(j = 0; j < k; j++){
      cin >> v;
      cin >> c;
      M[u][v] = c;
    }
  }
  dijkstra();
  return 0;
}

void dijkstra(){
  int minV;
  int d[MAX],color[MAX];
  int u,v;
  int i;
  for(i = 0; i < n; i++){
    d[i] = INFINITY;
    color[i] = WHITE;
  }
  d[0] = 0;
  color[0] = GRAY;
  while(1){
    minV = INFINITY;
    u = -1;
    for(i = 0; i < n; i++){
      if(minV > d[i] && color[i] != BLACK){
        u =i;
        minV = d[i];
      }
    }
    if(u == -1){
      break;
    }
    color[u] = BLACK;
    for(v = 0; v < n; v++){
      if(color[v] != BLACK && M[u][v] != INFINITY){
        if(d[v] > d[u] + M[u][v]){
          d[v] = d[u] + M[u][v];
          color[v] = GRAY;
        }
      }
    }
  }
  for(i = 0; i < n; i++){
    cout << i << " " << (d[i] == INFINITY ? -1 : d[i]) << endl;
  }
}