Orig Description
JOI Park
In preparation for the Olympics to be held in the IOI country in 20XX, it was decided to develop the JOI Park in the IOI country. JOI Park has N squares, and the squares are numbered from 1 to N. There are M roads that connect the squares, and the roads are numbered from 1 to M. Road i (1 ≤ i ≤ M) connects square Ai and square Bi bidirectionally, and its length is Di. It is possible to reach any square from any other square by following some roads.
In the development plan, first, an integer X greater than or equal to 0 is chosen, and all squares (including square 1) whose distance from square 1 is less than or equal to X are connected by an underground passage. Here, the distance between square i and square j is the minimum sum of the lengths of the roads that are traveled to go from square i to square j. The integer C related to the cost of building underground passages is determined in the development plan. The cost of building an underground passage is C × X.
Next, all roads that connect squares by an underground passage are removed. There is no cost for removing the roads. Finally, all the remaining roads are repaired. The cost of repairing a road of length d is d. There are no underground passages in the JOI Park before the development plan is implemented. Find the minimum sum of the costs required for development of the JOI Park.
Task
Given the information about the squares in the JOI Park and an integer related to the cost of building underground passages, write a program to find the minimum sum of the costs required for development of the JOI Park.
Input
The data is read from standard input in the following format:
The first line contains three integers N, M, and C, separated by a single space, indicating that there are N squares, M roads, and the integer related to the cost of building underground passages is C.
Among the following M lines, the i-th line (1 ≤ i ≤ M) contains three integers Ai, Bi, and Di, separated by a single space, indicating that road i connects square Ai and square Bi with a length of Di.
Output
Print a single integer to standard output, indicating the minimum sum of the costs required for development of the JOI Park.
Constraints
For all input data, the following conditions hold.
2 ≤ N ≤ 100,000.
1 ≤ M ≤ 200,000.
1 &le
Extracted Specification
An integer N (2 ≤ N ≤ 100,000), representing some quantity or size.
An integer M (1 ≤ M ≤ 200,000), representing some quantity or size.
An integer C, representing some quantity.
A list of M tuples, where each tuple contains three integers (A, B, D):
- A (1 ≤ A ≤ N), representing some quantity or size.
- B (1 ≤ B ≤ N), representing some quantity or size.
- D, representing some quantity.
### Example Input:
```
4 5 10
1 2 3
2 3 4
3 4 5
4 1 6
1 3 2
```
### Function Signature:
Write a function f(N, M, C, roads) that takes in the input.
```python
def f(N: int, M: int, C: int, roads: List[Tuple[int, int, int]]):
'''
N: an integer
M: an integer
C: an integer
roads: a list of tuples, where each tuple contains three integers
'''
```
Test Case Generator
To generate test cases for the given problem "JOI Park," we need to ensure that the generated input meets the specified constraints and structure. Here's a test case generator for this problem:
```python
import random
def tcgen():
# Constraints
N = random.randint(2, 100000) # Number of squares
M = random.randint(1, 200000) # Number of roads
C = random.randint(1, 1000) # Cost factor for underground passages
# Ensure we create a connected graph
edges = []
for i in range(1, N):
# Connect square i to square i+1 to guarantee connectivity
Ai = i
Bi = i + 1
Di = random.randint(1, 1000) # Random road length
edges.append((Ai, Bi, Di))
# Add additional random edges to meet the count M
while len(edges) < M:
Ai = random.randint(1, N)
Bi = random.randint(1, N)
if Ai != Bi:
Di = random.randint(1, 1000) # Random road length
edges.append((Ai, Bi, Di))
# Shuffle edges to randomize their order
random.shuffle(edges)
# Print the test case
print(N, M, C)
for edge in edges:
print(edge[0], edge[1], edge[2])
# Example usage
tcgen()
```
### Explanation:
1. **Number of Squares (N)**: Randomly selected between 2 and 100,000.
2. **Number of Roads (M)**: Randomly selected between 1 and 200,000.
3. **Cost Factor (C)**: Randomly selected within a reasonable range, e.g., between 1 and 1000.
4. **Edges**:
- First, a simplistic way to ensure the graph is connected is by connecting each consecutive pair of squares. This guarantees at least one path between any two squares.
- Then, additional edges are added until the desired number of roads (M) is reached.
- Each road's length (Di) is randomly chosen within a reasonable range for variety.
5. **Output**: The generated input is printed in the required format.
This generator ensures that the graph is connected and that the generated test cases meet the constraints specified in the problem statement. The lengths of roads and the cost factor for the underground passages are varied to create diverse test scenarios.
Extract Arguments
def extract_arguments(fh):
N, M, C = map(int, fh.readline().strip().split())
roads = []
for _ in range(M):
Ai, Bi, Di = map(int, fh.readline().strip().split())
roads.append((Ai, Bi, Di))
return N, M, C, roads
# if __name__ == "__main__":
# input_path = sys.argv[1]
# with open(input_path, 'r') as fh:
# N, M, C, roads = extract_arguments(fh)
# f(N, M, C, roads)