|
||||||||||
Equivalent SetsTime Limit: 12000/4000 MS (Java/Others) Memory Limit: 104857/104857 K (Java/Others)Total Submission(s): 8266 Accepted Submission(s): 2939 Problem Description To prove two sets A and B are equivalent, we can first prove A is a subset of B, and then prove B is a subset of A, so finally we got that these two sets are equivalent. You are to prove N sets are equivalent, using the method above: in each step you can prove a set X is a subset of another set Y, and there are also some sets that are already proven to be subsets of some other sets. Now you want to know the minimum steps needed to get the problem proved. Input The input file contains multiple test cases, in each case, the first line contains two integers N <= 20000 and M <= 50000. Next M lines, each line contains two integers X, Y, means set X in a subset of set Y. Output For each case, output a single integer: the minimum steps needed. Sample Input
Sample Output
Hint Case 2: First prove set 2 is a subset of set 1 and then prove set 3 is a subset of set 1. Source | ||||||||||
|