LightOJ - 1009
Description The Vampires and Lykans are fighting each other to death. The war has become so fierce that, none knows who will win. The humans want to know who will survive finally. But humans are afraid of going to the battlefield. So, they made a plan. They collected the information from the newspapers of Vampires and Lykans. They found the information about all the dual fights. Dual fight means a fight between a Lykan and a Vampire. They know the name of the dual fighters, but don't know which one of them is a Vampire or a Lykan. So, the humans listed all the rivals. They want to find the maximum possible number of Vampires or Lykans. Input Input starts with an integer T (≤ 10), denoting the number of test cases. Each case contains an integer n (1 ≤ n ≤ 105), denoting the number of dual fights. Each of the next n lines will contain two different integers u v (1 ≤ u, v ≤ 20000) denoting there was a fight between u and v. No rival will be reported more than once. Output For each case, print the case number and the maximum possible members of any race. Sample Input 2 2 1 2 2 3 3 1 2 2 3 4 2 Sample Output Case 1: 2 Case 2: 3 Source
Problem Setter: Jane Alam Jan
//题意:
有两个阵营,两个阵营各派一人对战,问对战n次后,人数更多的那个阵营的人数是多少?
开始用暴力写一直WA。。。下面的是参考大神的。
//思路:输入一个n,接下来n对人的对战情况 先用vector建图,将这n对对战的人存入图中,再用dfs查找赋值。因为可能有很多块,所以要 每次都加上每个块的最多的那个人数。最终所得即为所求
//这是我开始用暴力模拟写的,感觉对,但却WA到死,就是过不了。
|
LightOJ - 1009 Back to Underworld (vector&dfs)好题 判断两个阵营中最多人数
最新推荐文章于 2018-01-28 12:51:38 发布