Orig Description
C: Equivalent Propositions
Problem
There are $N$ propositions, each of which is named 1, 2, ..., $N$.
Also, information about propositions is given in $M$ pieces. The $i$-th information is given in the form of "$a_i$ $b_i$", which means that if $a_i$ is true, then $b_i$ is also true. ("If" is the logical implication and the transitive property holds.)
Output all propositions that are equivalent to each proposition $i$ in ascending order.
Proposition $i$ is always equivalent to proposition $i$.
Proposition $X$ and proposition $Y$ are equivalent if and only if "If $X$, then $Y$" and "If $Y$, then $X$" are both true.
Constraints
All input values are integers.
$2 \leq N \leq 300$
$1 \leq M \leq N(N-1)$
$a_i \neq b_i$
$1 \leq a_i, b_i \leq N$
Input Format
The input is given in the following format.
$N\ M$
$a_1\ b_1$
$a_2\ b_2$
$\vdots$
$a_M\ b_M$
Output
On the $i$-th line, output all propositions that are equivalent to proposition $i$ in ascending order, separated by a space. Also, output a newline at the end of each line.
Sample
Sample Input 1
5 2
1 2
2 1
Sample Output 1
1 2
1 2
3
4
5
Sample Input 2
3 3
1 2
2 3
3 1
Sample Output 2
1 2 3
1 2 3
1 2 3
Sample Input 3
6 7
1 2
1 3
2 6
3 4
4 5
5 3
6 2
Sample Output 3
1
2 6
3 4 5
3 4 5
3 4 5
2 6
Extracted Specification
An integer N (2 ≤ N ≤ 300), representing some quantity or size.
An integer M (1 ≤ M ≤ N(N-1)), representing another quantity or size.
M pairs of integers (a_i, b_i), where 1 ≤ a_i, b_i ≤ N and a_i ≠ b_i.
### Example Input:
```
5 2
1 2
2 1
```
### Function Signature:
Write a function f(N, M, pairs) that takes in the input.
def f(N: int, M: int, pairs: List[Tuple[int, int]]):
'''
N: an integer
M: an integer
pairs: a list of tuples, each containing two integers
'''
Test Case Generator
Sure, let's create a test case generator for the provided problem statement "Equivalent Propositions." The goal is to generate random test cases that adhere to the constraints and input format specified in the problem.
Here's the test case generator:
```python
import random
def generate_test_case():
# Step 1: Randomly generate N within the allowed range
N = random.randint(2, 300)
# Step 2: Generate a number of implication pairs, M
# Ensure M is within the valid range of 1 to N(N-1)
M = random.randint(1, min(N * (N-1), 5000))
# Step 3: Generate M pairs of implications (a_i, b_i)
implications = set()
while len(implications) < M:
a_i = random.randint(1, N)
b_i = random.randint(1, N)
if a_i != b_i:
implications.add((a_i, b_i))
# Convert set to list for consistent ordering
implications = list(implications)
# Step 4: Format the output
output = f"{N} {M}\n"
for a_i, b_i in implications:
output += f"{a_i} {b_i}\n"
return output
# Generate a test case and print it
print(generate_test_case())
```
This script generates a random number of propositions `N` and a random number of implication pairs `M` within the specified constraints. Each implication pair is unique and satisfies the conditions \(a_i \neq b_i\) and \(1 \leq a_i, b_i \leq N\).
Here is how it works:
1. **Randomly choose** \(N\) in the range from 2 to 300.
2. **Randomly choose** \(M\) in the range from 1 to \( \min(N(N-1), 5000) \), ensuring it doesn't exceed the maximum possible number of pairs.
3. **Generate unique pairs** \( (a_i, b_i) \), ensuring \( a_i \neq b_i \).
4. **Format the output** to match the required input format for the problem.
This generator ensures that all generated test cases are valid according to the problem constraints.
Extract Arguments
def extract_arguments(fh):
N, M = map(int, fh.readline().strip().split())
propositions = []
for _ in range(M):
a, b = map(int, fh.readline().strip().split())
propositions.append((a, b))
return N, M, propositions