Jellyfish
Time limit2sMemory limit512 MB
Given a connected graph with n vertices and n edges, find the largest set S where every subset T of S can be joined by a connected subgraph that avoids the other vertices of S.
- Level
Hard8 of 10
- Topics
- Graph, Tree, Dynamic programming, DFS
- Solved
- No attempts yet
Problem
Everyone knows that at Jagiellonian University we love plants a lot. We created hundreds of problems about trees, forests and even cacti. Unfortunately, problems about animals are not that popular. Today we want to prove that we love animals as well.
A graph is a jellyfish if it is a simple connected undirected graph with the same number of vertices and edges. You are given a jellyfish with vertices. For a subset of vertices , call an awesome subset if for every there exists a connected subgraph of the jellyfish that contains every vertex of and no other vertex of .
What is the maximum possible size of an awesome subset of ?
Input
The first line contains the number of test cases . The descriptions of the test cases follow.
The first line of each test case contains one integer (), the number of vertices of the jellyfish.
Each of the next lines contains two integers and (), describing one edge of the jellyfish. The given graph is guaranteed to be a jellyfish, and every two vertices are connected by at most one edge.
The total number of vertices in all test cases does not exceed .
Output
For each test case, output a single line containing one integer, the maximum possible size of an awesome subset of the jellyfish.