Beehives
Time limit2sMemory limit128 MB
Given a graph, find the smallest set of at least two vertices such that the induced subgraph is 2-edge-connected (no bridge disconnects the hive trees).
- Level
Hard8 of 10
- Topics
- Graph, Union-find, DFS
- Solved
- No attempts yet
Problem
Bees are among the most diligent insects. To gather nectar and pollen from flowers, they rely on the trees of the forest. To keep their work simple, the bees have numbered the trees from to . Instead of roaming the whole forest, they use only a fixed list of routes. Each route connects two trees, and the bees can travel it in either direction (in a straight line from one tree to the other). They never use a route that is not on the list.
As their techniques advanced, the bees changed the way they work. Rather than hovering over every tree in the forest, they decided to target only certain trees rich in flowers. So they plan to build new hives on some of those target trees. Once all the hives are built, the bees will gather food only from trees that have a hive, and they will delete some routes from the list so they never go to a tree without a hive; that is, only the routes between hive trees remain.
Now the bees want to build the hives. These hives must be such that, even if any single one of the routes is cut (a bird or animal on that route might disturb the bees), the bees can still travel between all hives using the remaining routes.
Because building a hive takes a lot of effort, the bees want to place hives on at least two trees while keeping their number as small as possible. Using the given trees and routes, propose a new colony of hives.
Input
The first line contains an integer (), the number of test cases.
Each case begins with one blank line. The next line contains two integers () and (), the number of trees and the number of routes. Each of the following lines contains two integers and (, ), denoting a route between tree and tree . There is at most one route between any pair of trees, and no route is given more than once.
Output
For each case, print Case X: (where X is the case number) followed by the number of hives in the proposed colony. If no such colony can be formed, print impossible instead of a number.
Hint
The input data is large. Use fast input/output.