Problem
Bees are one of the most industrious insects. Since they collect nectarand pollen from owers, they have to rely on the trees in the forest. For simplicity they numbered the n trees from 0 to n  1. Instead of roaming around all over the forest, they use a particular list of paths. A path is based on two trees, and they can move either way i.e. from one tree to another in straight line. They don’t use paths thatare not in their list.
As technology has been improved a lot, they also changed their working strategy. Instead of hovering over all the trees in the forest, they are targeting particular trees, mainly trees with lots of owers. So, they planned that they will build some new hives in some targeted trees. After that they will only collect their foods from these trees. They will also remove some paths from their list so that they don’t have to go to a tree with no hive in it.
Now, they want to build the hives such that if one of the paths in their new list go down (some
birds or animals disturbs them in that path) it’s still possible to go from any hive to another using the existing paths.
They don’t want to choose less than two trees and as hivebuilding requires a lot of work, they need to keep the number of hives as low as possible. Now you are given the trees with the paths they use, your task is to propose a new bee hive colony for them.
Input
Input starts with an integer T( T < 50), denoting the number of test cases.
Each case starts with a blank line. Next line contains two integers n (2 <= n <= 500) and m (0 < m< 20000), where n denotes the number of trees and m denotes the number of paths. Each of the next m lines contains two integers uv (0 < u , v < n), u = v) meaning that there is a path between tree u and v. Assume that there can be at most one path between tree u to v, and needless to say that a path will not be given more than once in the input.
Output
For each case, print the case number and the number of beehives in the proposed colony or impossible
if its impossible to find such a colony.
NOTE:
Dataset is huge. Use faster I/O methods.
Sample Input


Sample Output


Solution
題目描述：
在一個無向圖中，找到一個成本最小環。
題目解法：
Floyd 解法：
先來附一個錯誤版本，可以在 O(n^3)
解決，核心思路在於討論路徑上經過編號小於等於 k 時，同時探討最小環上經過編號 k 個所有環。但由於 n = 500
在此題中效率不好，但也不知道為什麼拿了 Runtime Error


BFS 作法：
Floyd 用在成本不同的路徑上是有效的，但是在成本都是 1 的時候就有點太過了，使用 BFS 對於每一個點進行最短路徑，查看路徑樹上是否有 back edge
。整體可以在 O(n^2)
完成，這個 back edge
可能會造成有重複走過點的環，但是不影響我們去找到最小成本。

