Orig Description
Problem D: One-Time Path
Problem
There are N islands and M bridges.
Each island is assigned a number from 1 to N.
Each bridge is assigned a number from 1 to M.
Gaccho is currently on the first island at time 0.
By using the i-th bridge, Gaccho can move unidirectionally from island ai to island bi.
However, at time 0, all the bridges are submerged underwater because of high tide.
The i-th bridge can be crossed when the tide goes out at time ci.
Once the tide comes in again after time ci, the bridge i will be submerged again, and Gaccho will assume that he can never cross the bridge again.
Gaccho wants to enjoy the scenery from island 1 to N-1 for as long as possible, but since he has a boat parked on island N, he must reach island N in the end.
Also, since he is waiting for his parents on the boat, Gaccho must leave for home as soon as he arrives at island N.
Since the time Gaccho spends crossing bridges or moving around islands is very short, it can be assumed to be 0.
Find the maximum time Gaccho can spend on any of the islands between 1 and N-1.
If Gaccho cannot move to island N no matter how he moves, output -1 instead.
Input
The input is given in the following format:
N M
a1 b1 c1
a2 b2 c2
…
aM bM cM
The first line contains two integers N and M separated by a space.
For each of the next M lines, three integers ai, bi, and ci are given separated by a space.
Constraints
2 ≤ N ≤ 105
1 ≤ M ≤ 2 × 105
1 ≤ ai < N
1 ≤ bi ≤ N
1 ≤ ci ≤ 109
ai ≠ bi
Output
If G
Extracted Specification
An integer N (2 ≤ N ≤ 10^5), representing some quantity or size.
An integer M (1 ≤ M ≤ 2 × 10^5), representing some other quantity or size.
A list of tuples (a, b, c) of size M, where each tuple contains three integers:
- a (1 ≤ a < N)
- b (1 ≤ b ≤ N)
- c (1 ≤ c ≤ 10^9)
- a ≠ b
### Example Input:
```
5 4
1 2 3
2 3 4
3 4 5
4 5 6
```
### Function Signature:
Write a function f(N, M, bridges) that takes in the input.
def f(N: int, M: int, bridges: List[Tuple[int, int, int]]):
'''
N: an integer
M: an integer
bridges: a list of tuples, where each tuple contains three integers (a, b, c)
'''
Test Case Generator
Certainly! Below is a test case generator for the `One-Time Path` problem statement. This generator will create random values adhering to the given constraints.
```python
import random
def tcgen():
# Generate random N and M within the constraints
N = random.randint(2, 10**5)
M = random.randint(1, 2 * 10**5)
bridges = []
for _ in range(M):
a = random.randint(1, N-1) # 1 ≤ ai < N
b = random.randint(1, N) # 1 ≤ bi ≤ N
while b == a: # Ensure ai ≠ bi
b = random.randint(1, N)
c = random.randint(1, 10**9) # 1 ≤ ci ≤ 10^9
bridges.append((a, b, c))
return N, M, bridges
def print_test_case():
N, M, bridges = tcgen()
print(N, M)
for a, b, c in bridges:
print(a, b, c)
# Example usage:
print_test_case()
```
### Explanation:
1. **N and M Generation**:
- `N` is chosen randomly between 2 and 100,000.
- `M` is chosen randomly between 1 and 200,000.
2. **Bridge Details Generation**:
- For each bridge, we generate `a` such that \( 1 \leq a < N \).
- We generate `b` such that \( 1 \leq b \leq N \) and ensure that \( a \neq b \) using a while loop.
- `c` is generated as a random value between 1 and 1,000,000,000.
3. **Output**:
- `print_test_case` prints a generated test case in the required format.
This code can be run to generate multiple test cases for the `One-Time Path` problem, ensuring a variety of inputs within the specified constraints.
Extract Arguments
def extract_arguments(fh):
N, M = map(int, fh.readline().strip().split())
bridges = []
for _ in range(M):
ai, bi, ci = map(int, fh.readline().strip().split())
bridges.append((ai, bi, ci))
return N, M, bridges
# if __name__ == "__main__":
# input_path = sys.argv[1]
# with open(input_path, 'r') as fh:
# N, M, bridges = extract_arguments(fh)
# f(N, M, bridges)