博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Lightoj1009——Back to Underworld(DFS)
阅读量:2343 次
发布时间:2019-05-10

本文共 1617 字,大约阅读时间需要 5 分钟。

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
Output for Sample Input
Case 1: 2
Case 2: 3

两个国家打仗,给出一些两方交战的数据,求两个国家可能的最大军队数,比如样例2:1、3、4就可能是某个国家最大的军队数,所以按照dfs遍历图,每隔一个点标记一个军队,因为敌人的敌人就是自己人。这个图可能不是连通图,所以需要全部遍历,把每个连通块的最大军队加起来

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#define INF 0x3f3f3f3f#define MAXN 200005#define Mod 10001using namespace std;int n,m,use[MAXN],vis[MAXN],sum,sum1;vector
mp[MAXN];void dfs(int x,bool flag){ sum++; if(flag) sum1++; vis[x]=1; for(int i=0;i

转载地址:http://tpcvb.baihongyu.com/

你可能感兴趣的文章
Ubuntu下apt-get与pip安装命令的区别
查看>>
linux CMakeLists.txt 语法
查看>>
cmake 简介
查看>>
CMake学习笔记(1)——用CMake编译一个hello world程序
查看>>
cmake使用总结---工程主目录CMakeList文件编写
查看>>
CMake学习之路
查看>>
cmake学习笔记6-catkin的CmakeList.txt讲解
查看>>
cmake手册详解
查看>>
Maplab框架介绍(一)
查看>>
Maplab开源VI-SLAM框架介绍
查看>>
maplab(1):安装
查看>>
陀螺仪随机误差的Allan方差分析
查看>>
Ubuntu 64位安装Adobe Reader 9.5.5
查看>>
Ubuntu 下如何查看已安装的软件
查看>>
Linux 系统下可以注释标注的pdf阅读器安装、比较和推荐
查看>>
福昕阅读器foxit reader Linux版
查看>>
Ubuntu 安装百度云客户端
查看>>
每天一个linux命令:locate
查看>>
Linux 环境下载百度云资源,Firefox插件(百度网盘助手)
查看>>
ubuntu Firefox/chrome adobe flash 插件安装
查看>>