Implement a function that calculates the maximum distance and associated cost for a series of test cases in an undirected graph. The function calculate_max_distance_and_cost(test_cases) should process each test case, perform a breadth-first search (BFS) to find the maximum distance from a starting point, and determine the cost based on that distance.
Input Requirements:
The function signature is def calculate_max_distance_and_cost(test_cases).
test_cases is a list of tuples. Each tuple represents a separate test case and contains:
An integer n (1 <= n <= 10000) indicating the number of vertices.
A list of edges, where each edge is represented as a tuple (x, y, z):
x: the starting vertex of the edge (1 ≤ x ≤ n).
y: the ending vertex of the edge (1 ≤ y ≤ n).
z: the weight of the edge between x and y (1 ≤ z ≤ 100).
Output Requirements:
The function should return a list of tuples, where each tuple corresponds to a test case and contains:
An integer representing the cost associated with the maximum distance.
An integer representing the maximum distance found in that test case.
Notes:
Ensure not to modify the input structure.
Use breadth-first search (BFS) to determine the maximum distance in the undirected graph.
The cost is calculated based on the following criteria:
If the maximum distance is less than 100, cost = 0.
If the maximum distance is between 100 and 999 (inclusive), cost = 100.
If the maximum distance is between 1000 and 9999 (inclusive), cost = 1000.
If the maximum distance is 10000 or more, cost = 10000.
Implementation:
Write your solution in a file named /app/solution.py with the complete function calculate_max_distance_and_cost as described above.