|
<p> |
|
The residents of Townsville have made it clear to the mayor that they're greatly concerned about gentrification, |
|
a process by which wealthy people move into the city in large numbers, displacing the people who currently |
|
live there. The mayor of Townsville knows a thing or two about this, and she would like to put the people's |
|
minds at ease by determining the worst-case scenario. |
|
</p> |
|
|
|
<p> |
|
Townsville is made up of <strong>N</strong> neighbourhoods, with <strong>M</strong> one-way roads running |
|
between them. The <strong>i</strong>th road runs from neighbourhood |
|
<strong>A<sub>i</sub></strong> to neighbourhood <strong>B<sub>i</sub></strong>. A swarm of rich migrants will |
|
move to the city all at once, immediately gentrifying any neighbourhood they decide to move into. |
|
</p> |
|
|
|
<p> |
|
The mayor knows the following facts about these new affluent residents: |
|
First, they like to visit other gentrified neighbourhoods. |
|
If there's a way of getting from their home neighbourhood to another gentrified neighbourhood, they will |
|
surely go visit. Second, they never walk anywhere; they only drive. Consequently, they'll get very angry if they end |
|
up in some neighbourhood with no way to drive back home. |
|
</p> |
|
|
|
<p> |
|
Putting these facts together, it means that |
|
if rich migrants move into and gentrify any two neighbourhoods <strong>u</strong> and <strong>v</strong>, |
|
then it must be the case that there is a series of roads connecting <strong>u</strong> to <strong>v</strong> |
|
if and only if there is a series of roads connecting <strong>v</strong> to <strong>u</strong>. |
|
</p> |
|
|
|
<p> |
|
Given this self-imposed constraint, and the layout of the roads in Townsville, what is the maximum number of neighbourhoods |
|
that can be gentrified? |
|
</p> |
|
|
|
|
|
<h3>Input</h3> |
|
<p> |
|
Input begins with an integer <strong>T</strong>, the number of test cases. |
|
For each test case, there is first a line containing the space-separated integers |
|
<strong>N</strong> and <strong>M</strong>. |
|
</p> |
|
|
|
<p> |
|
Then, <strong>M</strong> lines follow, the <strong>i</strong>th of which contains the space-separated integers |
|
<strong>A<sub>i</sub></strong> and <strong>B<sub>i</sub></strong>. |
|
</p> |
|
|
|
|
|
<h3>Output</h3> |
|
<p> |
|
For the <strong>i</strong>th test case, print a line containing "Case #<strong>i</strong>: " followed by |
|
the maximum possible number of gentrified neighbourhoods. |
|
</p> |
|
|
|
|
|
<h3>Constraints</h3> |
|
<p> |
|
1 ≤ <strong>T</strong> ≤ 20 <br /> |
|
1 ≤ <strong>N</strong> ≤ 500 <br /> |
|
1 ≤ <strong>M</strong> ≤ 20,000 <br /> |
|
0 ≤ <strong>A<sub>i</sub></strong>, <strong>B<sub>i</sub></strong> < <strong>N</strong> |
|
for all 1 ≤ <strong>i</strong> ≤ <strong>N</strong> <br /> |
|
<strong>A<sub>i</sub></strong> ≠ <strong>B<sub>i</sub></strong> |
|
for all 1 ≤ <strong>i</strong> ≤ <strong>N</strong> <br /> |
|
</p> |
|
|
|
|
|
<h3>Explanation of Sample</h3> |
|
<p> |
|
In the first test case, you can get from any neighbourhood to any other neighbourhood, so they can all be gentrified. |
|
<p> |
|
|
|
<p> |
|
In the second test case, any single neighbourhood can be gentrified, but that's it. If any two neighbourhoods are gentrified, |
|
there would be a path from one to the other, but no path back. |
|
</p> |
|
|