1009 - Back to Underworld
Time Limit: 4 second(s) Memory Limit: 32 MB

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 uand 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

Output for Sample Input

2

2

1 2

2 3

3

1 2

2 3

4 2

Case 1: 2

Case 2: 3

二分图染色

dfs

/* ***********************************************
Author :guanjun
Created Time :2016-6-12 15:28:00
File Name :1009.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 20100
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << ;
const double eps=1e-;
using namespace std; vector<int>edge[maxn];
int vis[maxn];
int a,b;
void init(){
cle(vis);
a=b=;
for(int i=;i<maxn;i++)edge[i].clear();
}
void dfs(int u,int k){
vis[u]=k;
if(k==)a++;
if(k==)b++;
for(int i=;i<edge[u].size();i++){
int v=edge[u][i];
if(!vis[v]){
dfs(v,-k);
}
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
int T,n,x,y;
cin>>T;
for(int t=;t<=T;t++){
init();
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d%d",&x,&y);
edge[x].push_back(y);
edge[y].push_back(x);
}
int ans=;
for(int i=;i<maxn;i++){
if(vis[i]==&&edge[i].size()){
a=;b=;
dfs(i,);
ans+=max(a,b);
}
} printf("Case %d: %d\n",t,ans);
}
return ;
}

最新文章

  1. ceph rgw s3 java sdk 上传大文件分批的方法
  2. Cocos2d-x 核心概念 - Node(节点)与Node层级架构
  3. java并发编程:并发容器之CopyOnWriteArrayList(转)
  4. [Linux][VMWare] 学习笔记之安装Linux系统-网络配置
  5. Gradient Boosting Decision Tree学习
  6. Android 并行自动化测试系统 实现总结
  7. boost线程的问题:
  8. 在MAC上安装虚拟机搭建Ubuntu开发环境
  9. 整理的Java资源
  10. 第9期Unity User Group Beijing图文报道:《Unity实战经验分享》
  11. Day2_元组_字典_集合_字符编码_文件处理
  12. manacher最长回文子串
  13. python的StringIO
  14. Orchard Core 自定义权限配置
  15. 软件开发架构、网络基础知识、osi七层模型
  16. R语言 vegan包计算物种累计曲线
  17. [转]Windows 注册自定义的协议
  18. 条款2:尽量以const, enum, inline替换#define
  19. centos6.6 下 安装 php7 按 nginx方式
  20. WIKI常用的表格设计模板

热门文章

  1. 算法导论 第九章 中位数和顺序统计量(python)
  2. 自定义UDF函数应用异常
  3. N个数求和(模拟)
  4. [USACO11NOV]牛的障碍Cow Steeplechase(匈牙利算法)
  5. 洛谷P1757 通天之分组背包
  6. 【贪心+DFS】D. Field expansion
  7. Cloud BOS平台-自定义用户联系对象
  8. python学习之-- redis模块操作 LIST
  9. PAT (Advanced Level) 1035. Password (20)
  10. ztr loves lucky numbers--hdu5676(DFS)