`
lilisalo
  • 浏览: 1106120 次
文章分类
社区版块
存档分类
最新评论

HDOJ/HDU 3836 Equivalent Sets

 
阅读更多

题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=3836

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
4 0 3 2 1 2 1 3

Sample Output
4 2
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

Recommend
xubiao


求强连通分量,然后统计每一个分量的入读和初读

这两个量中较大的那一个就是答案了。


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics