Implement a function that counts the total number of distinct cities that can be reached based on given road connections between cities.
Functionality Requirements:
Create a function count_cities_bought(test_cases) that takes a list of test cases, where each test case is a list of tuples. Each tuple represents a road between two cities.
Each city is identified by an integer.
For each test case, the function should calculate the total number of unique cities involved in the road connections and return a list of these counts for each test case.
Input Requirements:
The function will receive a list of test_cases, where:
Each test case is a list of tuples, and each tuple contains two integers (x, y), representing the two cities connected by a road.
The length of test_cases can vary, but each test case will contain at least one tuple.
Output Requirements:
The function should return a list of integers. Each integer corresponds to the count of distinct cities for the respective test case provided in the input.
Example:
python
input = [
[(1, 2), (2, 3), (4, 5)], # Test case 1
[(1, 1), (2, 3)], # Test case 2
[(5, 6), (6, 7), (5, 8)] # Test case 3
]
output = [5, 3, 4] # 5 distinct cities in test case 1, 3 in test case 2, and 4 in test case 3
Implementation:
The solution must be written in a file called /app/solution.py.