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>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

const int INF = 1001001001;

int main(){
  int n;
  cin >> n;
  vector<vector<pair<int, int>>> gr(n, vector<pair<int, int>>());
  rep(i, n){
    int a;
    cin >> a;
    int k;
    cin >> k;
    rep(j, k){
      int v, c;
      cin >> v >> c;
      gr.at(i).push_back(make_pair(v, c));
    }
  }
  vector<int> d(n, INF);
  vector<bool> chk(n, false);
  d.at(0) = 0;
  chk.at(0) = true;
  int now = 0;
  rep(i, n-1){
    for(auto p : gr.at(now)){
      if(chk.at(p.first) == true) continue;
      d.at(p.first) = min(d.at(p.first), d.at(now) + p.second);
    }
    int mn = INF, nx = -1;
    rep(j, n){
      if(chk.at(j) == true) continue;
      if(mn > d.at(j)){
        mn = d.at(j);
        nx = j;
      }
    }
    if(nx == -1) break;
    chk.at(nx) = true;
    now = nx;
  }

  rep(i, n){
    cout << i << " " << d.at(i) << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define MAX_V 100
#define INF (1 << 21)

struct edge { int to, cost; };
typedef pair<int, int> P;

int V;
vector<edge> G[MAX_V];
int d[MAX_V];

// int cost[MAX_V][MAX_V];
// bool used[MAX_V];

int s = 0; // start

void dijkstra()
{
    priority_queue<P, vector<P>, greater<P> > que;
    for (int i = 0; i < V; i++) {
        d[i] = INF;
        // used[i] = false;
    }
    d[s] = 0;
    que.push(P(0, s));

    for (; !que.empty();) {
        P p = que.top(); que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        for (int i = 0; i < G[v].size(); i++) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }

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

}
int main()
{
    cin >> V;

    // for (int i = 0; i < V; i++) {
    //     for (int j = 0; j < V; j++) {
    //         cost[i][j] = INF;
    //     }
    // }

    for (int i = 0; i < V; i++) {
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            int v, c;
            cin >> v >> c;
            G[u].push_back({v, c});
            // cost[u][v] = c;
        }
    }

    dijkstra();

    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxx=110;
const int infinity=(1<<21);

int A[maxx][maxx];
int d[maxx];
bool flag[maxx];

int main (){
	int n,a,b,c,minv,mini;
	cin>>n;
	for(int i=0;i<maxx;i++){
		flag[i]=false;
		d[i]=infinity;
		for(int j=0;j<maxx;j++){
			A[i][j]=infinity;
		}
	}
	for(int i=0;i<n;i++){
		cin>>a>>b;
		for(int j=0;j<b;j++){
			cin>>c>>A[a][c];
		}
	}
	
	d[0]=0;
	while(1){
		minv=infinity,mini=-1;
		for(int i=0;i<n;i++){
			if(flag[i]==false && d[i]<minv){
				minv=d[i];
				mini=i;
			}
		}
		if(mini==-1 || minv==infinity) break;
		flag[mini]=true;
		for(int i =0;i<n;i++){
			if(A[mini][i]!=infinity && flag[i]==false && d[mini]+A[mini][i]<d[i]){
					d[i]=d[mini]+A[mini][i];
			}
		}
		
	}
	cout<<n<<endl;
	int nn=n;
	for(int i=0;i<nn;i++) cout<<i<<" "<<d[i]<<endl;
	
	return 0;

}

C++: #include <iostream>

using namespace std;

int n;
int a[124][124] = {{}};
static const int INFTY = 1000000;

void dijkstra(){
  int flag[124] = {};
  int d[124] = {};
  int p[124] = {};
  int minv;
  int u;

  for (int i = 0;i < n;i++){
    d[i] = INFTY;
    p[i] = -1;
  }
  d[0] = 0;
  while(1){
    minv = INFTY;
    u = -1;

    for(int i = 0;i < n;i++){
      if(flag[i] == 0 && minv > d[i]){
        minv = d[i];
        u = i;
      }
    }
  //  cout << "u = " << u << endl;
  //  cout << "minv = " << minv << endl;
    if(u == -1) break;
    flag[u] = 1;

    for(int i = 0;i < n;i++){
      if(d[i] > d[u] + a[u][i] && a[u][i] != INFTY && flag[i] == 0){
        d[i] = d[u] + a[u][i];
        p[i] = u;
      }
    }
  }

  for(int i = 0;i < n;i++){
    if(d[i] != -1){
      cout << i <<  " " << d[i] << endl;
    }
    else cout << i << " " << -1 << endl;
  }
}



int main(){

  cin >> n;

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


  int u;
  int k;
  for(int i = 0;i < n;i++){
    cin >> u >> k;
    for (int j = 0;j < k;j++){
      int v;
      cin >> v;
      cin >> a[u][v];
    }
  }
  dijkstra();
}