Problem p03722 - Generation 3

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 some quantity or size.
M lines follow, each containing three integers a, b, and c:
- a (1 ≤ a ≤ N)
- b (1 ≤ b ≤ N)
- c (-10^9 ≤ c ≤ 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.
```python
def f(N: int, M: int, edges: List[Tuple[int, int, int]]):
    '''
    N: an integer
    M: an integer
    edges: a list of tuples, each containing three integers
    '''
```

Test Case Generator

Sure, let's write a test case generator for the given problem statement. The generator will create random values for \(N\), \(M\), and the edges with their weights, ensuring the constraints are met.

Here's the Python code to generate the test cases:

```python
import random

def generate_test_case():
    # Constraints
    N = random.randint(2, 1000)
    max_edges = min(N * (N - 1), 2000)
    M = random.randint(1, max_edges)
    
    edges = set()
    while len(edges) < M:
        a = random.randint(1, N)
        b = random.randint(1, N)
        if a != b:
            c = random.randint(-10**9, 10**9)
            edges.add((a, b, c))
    
    edges = list(edges)
    random.shuffle(edges)

    return N, M, edges

def print_test_case():
    N, M, edges = generate_test_case()
    print(N, M)
    for a, b, c in edges:
        print(a, b, c)

# Uncomment the following line to generate and print a test case
# print_test_case()
```

### Explanation:
1. **N** is chosen randomly between 2 and 1000.
2. **M** is chosen randomly between 1 and `min(N*(N-1), 2000)`.
3. We create a set of edges to ensure all edges are unique and adhere to the constraints.
4. For each edge, we ensure \(a \neq b\) and the weight \(c\) is between \(-10^9\) and \(10^9\).
5. We shuffle the edges to ensure randomness in their order.
6. Finally, we print \(N\), \(M\), and the list of edges.

This generator ensures that all constraints are respected, and it produces diverse and realistic test cases for the problem.

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