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>
#include<vector>
#include<stack>

#define INF (1 << 21)

int main() {
	int node_num;

	std::cin >> node_num;
	std::vector<std::vector<int> > node(node_num, std::vector<int>(node_num, -1));

	for (size_t i = 0; i < node.size(); i++) {
		int out, node_number;
		std::cin >> node_number >> out;
		for (int j = 0; j < out; j++) {
			int to, distance;
			std::cin >> to >> distance;
			node[node_number][to] = distance;
		}
	}

	std::vector<int> distance(node.size(), INF);
	std::stack<int> s;
	distance[0] = 0;

	s.push(0);
	while(!s.empty()) {
		int node_number = s.top(); s.pop();
		for (size_t j = 0; j < node[node_number].size(); j++) {
			if (node[node_number][j] != -1 && node[node_number][j] + distance[node_number] < distance[j]) {
				distance[j] = node[node_number][j] + distance[node_number];
				s.push(j);
			}
		}
	}

	for (size_t i = 0; i < distance.size(); i++) {
		std::cout << i << " " << distance[i] << std::endl;
	}
}

C++: #include <iostream>
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
static const int MAX = 2000;

int d[110], p[110];
int color[110];

int main() {
  int n;
  std::cin >> n;
  int G[110][110];

  for(int i=0; i<n; ++i) {
    for(int j=0; j<n; ++j) {
      int v;
      std::cin >> v;
      if(v != -1) {
        G[i][j] = v;
      } else {
        G[i][j] = MAX;
      }
    }
  }

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

  d[0] = 0;
  p[0] = 0;

  while(true) {
    int mini_cost = MAX;
    int u;
    // 最小の重みとなる辺を探している
    for(int i=0; i<n; ++i) {
      if(color[i] != BLACK && d[i] < mini_cost) {
        mini_cost = d[i];
        u = i;
      }
    }

    if(mini_cost == MAX) {
      break;
    }

    color[u] = BLACK;

    for(int v=0; v < n; ++v) {
      if(color[v] != BLACK && G[u][v] != MAX) {
        if(G[u][v] < d[v]) {
          d[v] = G[u][v];
          p[v] = u;
          color[v] = GRAY;
        }
      }
    }
  }

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

  std::cout << d_sum << std::endl;
}

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

#define MAX_VERTEX  100
#define INF         1000000

int vertex_num;                   // ???????????°

int cost[MAX_VERTEX][MAX_VERTEX]; // ????????????cost[?§????][??????]??§?§?????????????????????????????????¨???
int d[MAX_VERTEX];                // ????????????d[u]??§?§??????¨u??????????????¢?????¨??????
bool used[MAX_VERTEX];            // ????????????????????£????????¢????±???????????????????

void Input() {
	cin >> vertex_num;

	// (a1) ??\???????????¶??§?????????

	// d??¨cost?????¨???INF
	// used????????????false
  for (int i = 0; i < vertex_num; i++) {
    d[i] = INF;
    used[i] = false;
    for (int j = 0; j < vertex_num; j++) {
      cost[i][j] = INF;
    }
  }

	for (int i = 0; i < vertex_num; i++) {
		int from, out_num;
		cin >> from >> out_num;
		for (int j = 0; j < out_num; j++) {
			int to, c;
			cin >> to >> c;
			cost[from][to] = c;
		}
	}
}

void Dijkstra() {

	// (b1) ?§????????????????
  d[0]    = 0;

	while (true) {
		// ????????????????????¨???
		int vertex = -1;

		// (b2) ????????????????????£????????¢????±??????????????????????
		// ?????????????????????????????????????????§????????¢???????°???????????????¢???
    for(int u = 0; u < vertex_num; u++) {
      if(!used[u] && (vertex == -1 || d[u] < d[vertex])) {
        vertex = u;
      }
    }

		// ??¨????????????????????????????¨?????????????????????´????????????????????????
		if (vertex == -1) {
      break;
    }

		used[vertex] = true;

		// ???????????¢????¨????????????????
    for(int u = 0; u < vertex_num; u++) {
      d[u] = min(d[u], d[vertex] + cost[vertex][u]);
    }

	}

}

void Output() {
	for (int i = 0; i < vertex_num; i++) {
		cout << i << " " << d[i] << endl;
	}
}

int main() {

	Input();
	Dijkstra();
	Output();

	return 0;
}

C++: #include<cstdio>
#define INF 200001 
 
int main(){
 int u,k,C,V,A[1000][1000],D[1000][1000],n;
  scanf("%d",&n);
   for(int i=0;i<n;i++)for(int j=0;j<n;j++)D[i][j] = INF;
  for(int i=0;i<n;i++){
      scanf("%d %d",&u,&k);    
      for(int j=0;j<k;j++){
    scanf("%d %d",&V,&C);
    D[u][V] = C;
      }    
  }
  for(int i=0;i<n;i++)D[i][i] = 0;
  for(int k=0;k<n;k++)for(int i=0;i<n;i++)for(int j=0;j<n;j++)D[i][j]= min(D[i][j],D[i][k] + D[k][j]);
  for(int i=0;i<n;i++)printf("%d %d\n",i,D[0][i]);
  return 0;
}