Orig Description
Score : 400 points
Problem StatementFennec and Snuke are playing a board game.
On the board, there are N cells numbered 1 through N, and N-1 roads, each connecting two cells. Cell a_i is adjacent to Cell b_i through the i-th road. Every cell can be reached from every other cell by repeatedly traveling to an adjacent cell. In terms of graph theory, the graph formed by the cells and the roads is a tree.
Initially, Cell 1 is painted black, and Cell N is painted white. The other cells are not yet colored.
Fennec (who goes first) and Snuke (who goes second) alternately paint an uncolored cell.
More specifically, each player performs the following action in her/his turn:
Fennec: selects an uncolored cell that is adjacent to a black cell, and paints it black.
Snuke: selects an uncolored cell that is adjacent to a white cell, and paints it white.
A player loses when she/he cannot paint a cell. Determine the winner of the game when Fennec and Snuke play optimally.
Constraints
2 \leq N \leq 10^5
1 \leq a_i, b_i \leq N
The given graph is a tree.
InputInput is given from Standard Input in the following format:
N
a_1 b_1
:
a_{N-1} b_{N-1}
OutputIf Fennec wins, print Fennec; if Snuke wins, print Snuke.
Sample Input 17
3 6
1 2
3 1
7 4
5 7
1 4
Sample Output 1Fennec
For example, if Fennec first paints Cell 2 black, she will win regardless of Snuke's moves.
Sample Input 24
1 4
4 2
2 3
Sample Output 2Snuke
Extracted Specification
An integer N (2 ≤ N ≤ 10^5), representing some quantity or size.
A list of tuples where each tuple contains two integers a_i and b_i (1 ≤ a_i, b_i ≤ N).
### Example Input:
```
7
3 6
1 2
3 1
7 4
5 7
1 4
```
### Function Signature:
Write a function f(N, edges) that takes in the input.
def f(N: int, edges: List[Tuple[int, int]]):
'''
N: an integer
edges: a list of tuples, each containing two integers
'''
Test Case Generator
Sure, I can create a test case generator for the problem you've provided. The problem involves generating a tree with \( N \) nodes and \( N-1 \) edges. Since the input size can be as large as \( 10^5 \), we'll ensure to generate valid trees and format them appropriately.
Here is a Python function that generates such test cases:
```python
import random
import sys
def generate_tree(N):
edges = []
for i in range(2, N+1):
edges.append((i, random.randint(1, i-1)))
random.shuffle(edges)
return edges
def tcgen():
N = random.randint(2, 10**5)
edges = generate_tree(N)
test_case = f"{N}\n"
for a, b in edges:
test_case += f"{a} {b}\n"
return test_case
# Example usage:
if __name__ == "__main__":
sys.setrecursionlimit(200000)
print(tcgen())
```
### Explanation
1. **generate_tree(N)**:
- This function generates a tree with \( N \) nodes by ensuring that each node \( i \) (from 2 to \( N \)) is connected to a random previous node (between 1 and \( i-1 \)). This guarantees that the generated structure forms a valid tree.
2. **tcgen()**:
- This function uses `generate_tree(N)` to get the edges for the tree.
- The edges are then formatted according to the problem's input specification and returned as a single string.
### How to Use
- Run the script, and it will print a randomly generated test case to the standard output.
- Each time you run the script, it generates a new test case with a different tree structure.
### Note
- The generated tree ensures that every node is connected, making the graph a valid tree.
- The recursion limit is set higher to accommodate deeper recursive calls that might occur with trees having nodes close to the upper limit.
You can modify the `sys.setrecursionlimit` if your environment requires it for handling large trees, or you can further adjust the generator for specific needs or constraints.
Extract Arguments
def extract_arguments(fh):
N = int(fh.readline().strip())
edges = []
for _ in range(N - 1):
a, b = map(int, fh.readline().strip().split())
edges.append((a, b))
return N, edges