Time limit
1s
Memory limit
128 MB
A university has n students. You want to know the maximum possible number of different religions believed in by the students, but asking every student directly is impractical, and some students may not want to state their beliefs.
Instead, you are given m pairs of students where each pair is known to believe in the same religion. From this information, you may not know each student's exact religion, but you can determine the maximum number of different religions that could still be present on campus.
Assume that each student believes in at most one religion. The number of students satisfies 0 < n <= 50000, and the number of relations satisfies 0 <= m <= n(n-1)/2.
The input contains multiple test cases. Each test case starts with a line containing two integers n and m.
The next m lines each contain two integers i and j, meaning that student i and student j believe in the same religion. Students are numbered from 1 to n.
A line with n = 0 and m = 0 ends the input.
For each test case, print one line in the format Case x: y. Here x is the test case number starting from 1, and y is the maximum possible number of different religions among the students that is consistent with the given information.