Untitled

mail@pastecode.io avatar
unknown
c_cpp
a year ago
1.1 kB
1
Indexable
#include <iostream>
#include <vector>

using namespace std;

int shortestPath(int N, int X, int Y) {
  // Create a vector to store the number of pairs of cities having shortest path between them k.
  vector<int> shortestPaths(N + 1, 0);

  // Initialize the adjacency list.
  vector<vector<int>> adjList(N + 1);
  for (int i = 1; i <= N; i++) {
    adjList[i].push_back(i + 1);
  }

  // Add the edge between X and Y.
  adjList[X].push_back(Y);
  adjList[Y].push_back(X);

  // Find the shortest paths between all pairs of cities.
  for (int i = 1; i <= N; i++) {
    for (int j = i + 1; j <= N; j++) {
      int shortestPath = 1;
      for (int k = i + 1; k < j; k++) {
        shortestPath = min(shortestPath, shortestPath(i, k) + shortestPath(k, j));
      }
      shortestPaths[shortestPath]++;
    }
  }

  return shortestPaths;
}

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;

  vector<int> shortestPaths = shortestPath(N, X, Y);

  for (int i = 1; i <= N; i++) {
    cout << shortestPaths[i] << " ";
  }

  cout << endl;

  return 0;
}