Implement the functionality to calculate the minimum and maximum number of road rebuilds required to travel along a specified path in a road network represented as a directed graph.
Functionality Requirements
You need to implement the function calculate_rebuilds(n, m, roads, k, path) based on the provided signature and implementation outline. This function should:
Accept the number of intersections n, the number of roads m, a list of tuples roads representing each directed road between intersections, the length of the path k, and a list of intersections path which denotes the specific route taken.
Determine the minimum number of road rebuilds necessary (ans1) and the maximum number of road rebuilds possible (ans2) to follow the path from the last intersection back to the first in reverse using a breadth-first search (BFS) approach.
Return a tuple containing both ans1 and ans2.
Input Requirements
n (1 ≤ n ≤ 1000): The number of intersections.
m (1 ≤ m ≤ 2000): The number of directed roads.
roads (a list of tuples): Each tuple (u, v) denotes a directed road from intersection u to intersection v with 1 ≤ u, v ≤ n.
k (1 ≤ k ≤ n): The number of intersections in the path.
path (a list of integers): The sequence of intersections that constitutes the path, with each value between 1 and n.
Output Requirements
Return a tuple (ans1, ans2) where:
ans1 is the minimum number of road rebuilds.
ans2 is the maximum number of road rebuilds.
Implementation
You must write the solution in a file called /app/solution.py. The file should contain the complete implementation of the function calculate_rebuilds as described above. Ensure proper handling of inputs and the implemented algorithm works efficiently given the constraints.