Problem p00268 - Generation 1

Orig Description

Cat Going Straight II
There is a large old mansion somewhere, and a cat has settled in it. The mansion is a convex polygon when viewed from above, and is made up of several rooms surrounded by straight walls. One wall is supported by pillars at both ends, as shown in the figure. Since the mansion is very old, there is a hole in each wall that a cat can pass through. The cat can pass through the hole in the wall to go back and forth between the rooms in the mansion or between the rooms and the outside.
The owner of the mansion blows a whistle to call the cat out of the mansion to give it food. The cat is very clever and when the owner blows the whistle, it goes out of the mansion by making "the best choice" which means passing the hole in the wall the fewest number of times.
The cat is very capricious and the time it takes to go out of the mansion varies from day to day, and the owner is puzzled because he does not know how long to wait. One day, the owner noticed that it took the cat a long time to pass through the hole in the wall. That means the time it takes for the cat to go out is determined by the number of times it passes through the hole. The owner thought that if he knew the maximum number of times the cat would pass through the hole when it made "the best choice", he would know how long to wait even if he didn't know which room the cat was in. The owner knows the layout of the mansion, but it is too large for him to calculate on his own...
Write a program that reads the layout of the mansion and outputs the maximum number of holes the cat passes through before going outside when it makes "the best choice".
Input
The input consists of multiple datasets. The end of the input is indicated by two zeros. Each dataset is given in the following format.
C W
x1 y1
x2 y2
:
xC yC
s1 t1
s2 t2
:
sW tW
Each number given in a line is separated by a single space.
The first line contains the number of pillars C (3 ≤ C ≤ 100) and the number of walls W (3 ≤ W ≤ 300). The coordinates of the pillars are given in the following C lines. xi (-1000 ≤ xi ≤ 1000) is the x-coordinate of the i-th pillar, and yi (-1000 ≤ yi ≤ 1000) is the y-coordinate of the i-th pillar. Each pillar is assigned a number from 1 to C. The information of the walls is given in the following W lines.
si (1 ≤ si ≤ C) and ti (1 ≤ ti ≤ C) indicate the numbers of the pillars that support the ends of the wall.
It can be assumed that the input satisfies the following conditions.
 No two pillars occupy the same position.
 No two different walls overlap or cross at a location other than a pillar.
 A single pillar supports two or more walls.
 The length of the wall is greater than zero.
 The pillar is only located at the ends of the wall. In other words, the pillar is not in the middle of the wall.
 The wall separates different rooms or rooms and the outside.
 Any two different pillars can be reached by following the walls.
The number of datasets does not exceed 50.
Output
For each dataset, output the maximum number of holes the cat passes through before going outside when it makes "the best choice" on a line.
Sample Input
4 4
0 0
1 0
1 1
0 1
1 2
1 4
2 3
3 4
12 22
2 0
4 0
8 0
4 2
6 2
8 2
2 4
4 4
6 4
0 6
8 6
0 8
1 2
2 3
1 4
1 7
1 10
2 4
2 5
3 5
3 6
4 5
4 8
5 6
5 9
6 9
6 11
7 10
7 8
8 9
9 11
10 11
10 12
11 12
0 0
Sample Output
1
3
The second dataset corresponds to the floor plan of the mansion shown at the beginning of the text. When the cat is in the room with a lightly colored background, it passes through three holes to go outside by making "the best choice". When the cat is in any other room, it can go out with two or fewer holes. Therefore, the maximum number of holes the cat passes through before going outside when it makes "the best choice" is three.

Extracted Specification

An integer C (3 ≤ C ≤ 100), representing some quantity.
An integer W (3 ≤ W ≤ 300), representing some quantity.
C pairs of integers (x, y), where each integer is between -1000 and 1000.
W pairs of integers (s, t), where each integer is between 1 and C.
Multiple datasets terminated by the pair 0 0.

### Example Input:

```
4 4
0 0
1 0
1 1
0 1
1 2
1 4
2 3
3 4
0 0
```

### Function Signature:
Write a function f(inputs) that takes in the input. 
def f(inputs: List[Tuple[int, int, List[Tuple[int, int]], List[Tuple[int, int]]]]): 
    ''' 
    inputs: a list of tuples, each containing:
        - an integer C
        - an integer W
        - a list of C tuples, each with two integers (x, y)
        - a list of W tuples, each with two integers (s, t)
    '''

Test Case Generator

Sure, I can help you write a test case generator for the competitive programming problem "Cat Going Straight II". Below is the Python code that generates test cases for this problem:

```python
import random

def generate_pillars(C):
    # Generating C unique pillars with coordinates between -1000 and 1000
    pillars = set()
    while len(pillars) < C:
        x = random.randint(-1000, 1000)
        y = random.randint(-1000, 1000)
        pillars.add((x, y))
    return list(pillars)

def generate_walls(C, W):
    # Generating W walls based on C pillars (1-indexed)
    walls = set()
    while len(walls) < W:
        s = random.randint(1, C)
        t = random.randint(1, C)
        if s != t:
            # Ensure no duplicate walls and no wall with the same pillar at both ends
            wall = tuple(sorted((s, t)))
            walls.add(wall)
    return list(walls)

def tcgen():
    # Generate number of pillars and walls
    C = random.randint(3, 100)
    W = random.randint(3, 300)
    
    # Generate pillars' coordinates
    pillars = generate_pillars(C)
    
    # Generate walls using the pillars
    walls = generate_walls(C, W)
    
    # Formatting the test case
    test_case = f"{C} {W}\n"
    
    for x, y in pillars:
        test_case += f"{x} {y}\n"
    
    for s, t in walls:
        test_case += f"{s} {t}\n"
    
    return test_case

# Generate multiple test cases
num_test_cases = 5
for _ in range(num_test_cases):
    print(tcgen())
    print("0 0")
```

### Explanation:

1. **Generating Pillars**:
   - We generate `C` unique pillars with coordinates between -1000 and 1000. The set data structure ensures that each pillar has unique coordinates.

2. **Generating Walls**:
   - We generate `W` walls, each defined by two distinct pillars. The walls are represented by tuples of pillar indices, and we use a set to avoid duplicate walls.

3. **Formatting the Test Case**:
   - We format the pillars and walls into the input format specified in the problem statement.

4. **Generating Multiple Test Cases**:
   - We loop to generate multiple test cases and print each one, followed by the `0 0` termination line.

This script generates random valid test cases that you can use to test your solution for the "Cat Going Straight II" problem.

Extract Arguments

def extract_arguments(fh):
    datasets = []
    while True:
        C, W = map(int, fh.readline().strip().split())
        if C == 0 and W == 0:
            break
        coordinates = [tuple(map(int, fh.readline().strip().split())) for _ in range(C)]
        walls = [tuple(map(int, fh.readline().strip().split())) for _ in range(W)]
        datasets.append((C, W, coordinates, walls))
    return datasets