Problem p03722 - Generation 2

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 other quantity or size.
A list of M tuples, where each tuple contains two integers and one more integer, all three of which are between -10^9 and 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, where each tuple contains three integers
    '''

Test Case Generator

Sure, I can help write a test case generator for this problem. Here is the generator function that will create random test cases for the graph problem described:

```python
import random

def tcgen():
    # Number of vertices
    N = random.randint(2, 1000)
    
    # Number of edges
    max_edges = min(N * (N - 1), 2000)
    M = random.randint(1, max_edges)
    
    edges = set()
    
    # Ensure there's a path from 1 to N
    path = list(range(1, N + 1))
    random.shuffle(path)
    
    for i in range(1, N):
        a = path[i - 1]
        b = path[i]
        c = random.randint(-10**9, 10**9)
        edges.add((a, b, c))
    
    # Add additional random edges
    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)
    
    # Print the generated test case
    print(f"{N} {M}")
    for a, b, c in edges:
        print(f"{a} {b} {c}")

# Example usage
tcgen()
```

**Explanation:**

1. The number of vertices \( N \) is randomly chosen between 2 and 1000.
2. The number of edges \( M \) is randomly chosen between 1 and the minimum of \( N(N-1) \) and 2000.
3. A set of edges is used to avoid duplicate edges.
4. A path ensuring connectivity from vertex 1 to vertex \( N \) is created by shuffling a range from 1 to \( N \) and ensuring each vertex connects to the next in the shuffled list.
5. Additional random edges are added until the number of edges \( M \) is reached.
6. The edges are shuffled and printed in the required format.

You can call the `tcgen` function to generate and print a random test case 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
    
# 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)