Orig Description
Score : 400 points
Problem StatementThere is a directed graph with N vertices and M edges.
The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i.
We will play the following single-player game using this graph and a piece.
Initially, the piece is placed at vertex 1, and the score of the player is set to 0.
The player can move the piece as follows:
When the piece is placed at vertex a_i, move the piece along the i-th edge to vertex b_i. After this move, the score of the player is increased by c_i.
The player can end the game only when the piece is placed at vertex N.
The given graph guarantees that it is possible to traverse from vertex 1 to vertex N.
When the player acts optimally to maximize the score at the end of the game, what will the score be?
If it is possible to increase the score indefinitely, print inf.
Constraints
2≤N≤1000
1≤M≤min(N(N-1),2000)
1≤a_i,b_i≤N (1≤i≤M)
a_i≠b_i (1≤i≤M)
a_i≠a_j or b_i≠b_j (1≤i
Extracted Specification
An integer N (2 ≤ N ≤ 1000), representing some quantity or size.
An integer M (1 ≤ M ≤ min(N(N-1), 2000)), representing another quantity or size.
M tuples of three integers each (a_i, b_i, c_i) where:
- 1 ≤ a_i, b_i ≤ N
- a_i ≠ b_i
- -10^9 ≤ c_i ≤ 10^9
### Example Input:
```
3 3
1 2 4
2 3 3
1 3 5
```
### Function Signature:
Write a function f(N, M, edges) that takes in the input.
def f(N: int, M: int, edges: List[Tuple[int, int, int]]):
'''
N: an integer
M: an integer
edges: a list of tuples of three integers
'''
Test Case Generator
To generate test cases for the given problem statement where we have a directed graph with \(N\) vertices and \(M\) edges, we need to ensure the constraints and properties mentioned in the problem statement are followed. Here's a Python function to generate such test cases:
```python
import random
def generate_test_case():
N = random.randint(2, 1000) # Number of vertices
M = random.randint(1, min(N * (N - 1), 2000)) # Number of edges
edges = set()
while len(edges) < M:
a = random.randint(1, N)
b = random.randint(1, N)
if a != b:
edges.add((a, b))
edges = list(edges)
edge_weights = [random.randint(-10**9, 10**9) for _ in range(M)]
test_case = f"{N} {M}\n"
for (a, b), c in zip(edges, edge_weights):
test_case += f"{a} {b} {c}\n"
return test_case
# Example of generating and printing a test case
print(generate_test_case())
```
### Explanation:
1. **Vertices (N)**: Randomly choose a value for \(N\) between 2 and 1000.
2. **Edges (M)**: Randomly choose a value for \(M\) between 1 and the minimum of \(N(N-1)\) and 2000. This ensures we don't exceed the maximum number of edges as per the given constraints.
3. **Unique Edges**: Use a set to ensure all edges \((a_i, b_i)\) are unique and \(a_i \neq b_i\).
4. **Edge Weights**: Randomly assign weights to each edge within the range \([-10^9, 10^9]\).
5. **Output Format**: Construct the test case in the required format.
This function guarantees the generated test cases are well within the problem constraints, and ensures the graph properties required for the problem are maintained.
Extract Arguments
def extract_arguments(fh):
N, M = map(int, fh.readline().strip().split())
edges = []
for _ in range(M):
a, b, c = map(int, fh.readline().strip().split())
edges.append((a, b, c))
return N, M, edges
# if __name__ == "__main__":
# input_path = sys.argv[1]
# with open(input_path, 'r') as fh:
# N, M, edges = extract_arguments(fh)
# f(N, M, edges)