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 ;
}

Lightoj 1009 - Back to Underworld的更多相关文章

  1. Back to Underworld(lightoj 1009)

    1009 - Back to Underworld    PDF (English) Statistics Forum Time Limit: 4 second(s) Memory Limit: 32 ...

  2. LightOJ 1009 二分图染色+BFS/种类并查集

    题意:有两个阵营的人,他们互相敌对,给出互相敌对的人,问同个阵营的人最多有多少个. 思路:可以使用种类并查集写.也可以使用使用二分图染色的写法,由于给定的点并不是连续的,所以排序离散化一下,再进行BF ...

  3. Back to Underworld(搜索)

    Back to Underworld Time Limit:4000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Su ...

  4. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. 1009: [HNOI2008]GT考试

    1009: [HNOI2008]GT考试 Time Limit: 1 Sec Memory Limit: 162 MB Description 阿申准备报名参加GT考试,准考证号为N位数\(X_1X_ ...

  6. 区间DP LightOJ 1422 Halloween Costumes

    http://lightoj.com/volume_showproblem.php?problem=1422 做的第一道区间DP的题目,试水. 参考解题报告: http://www.cnblogs.c ...

  7. LightOj 1298 - One Theorem, One Year(DP + 欧拉)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1298 题意:给你两个数 n, p,表示一个数是由前 k 个素数组成的,共有 n 个素数 ...

  8. 1214 - Large Division -- LightOj(大数取余)

    http://lightoj.com/volume_showproblem.php?problem=1214 这就是一道简单的大数取余. 还想还用到了同余定理: 所谓的同余,顾名思义,就是许多的数被一 ...

  9. LightOJ Beginners Problems 部分题解

    相关代码请戳 https://coding.net/u/tiny656/p/LightOJ/git 1006 Hex-a-bonacci. 用数组模拟记录结果,注意取模 1008 Fibsieve's ...

随机推荐

  1. [Docker]容器镜像

     1.rootfs的基础知识 Mount namespaces 隔离的是文件系统挂接点,它使每个容器能看到不同的文件系统层次结构,即每当创建一个新容器时,希望容器进程看到的文件系统时一个独立的隔离环境 ...

  2. hust 1017 dancing links 精确覆盖模板题

    最基础的dancing links的精确覆盖题目 #include <iostream> #include <cstring> #include <cstdio> ...

  3. UVA 11090 判负圈问题

    题目链接http://vjudge.net/problem/viewProblem.action?id=34650 题目大意: 给定n个点m条边的加权有向图,求平均权值最小的回路.平均权值=路径权值之 ...

  4. 洛谷P1504 积木城堡

    题目描述 XC的儿子小XC最喜欢玩的游戏用积木垒漂亮的城堡.城堡是用一些立方体的积木垒成的,城堡的每一层是一块积木.小XC是一个比他爸爸XC还聪明的孩子,他发现垒城堡的时候,如果下面的积木比上面的积木 ...

  5. SkyWalking 分布式追踪系统

    随着微服务架构的流行,一些微服务架构下的问题也会越来越突出,比如一个请求会涉及多个服务,而服务本身可能也会依赖其他服务,整个请求路径就构成了一个网状的调用链,而在整个调用链中一旦某个节点发生异常,整个 ...

  6. linux service命令解析(重要)

    我们平时都会用service xxx start来启动某个进程,那么它背后究竟执行了什么? 其实service的绝对路径为/sbin/service ,打开这个文件cat /sbin/service, ...

  7. Arduino学习笔记0---开发板的了解

    Arduino的入门文档https://wenku.baidu.com/view/4040861d58fafab069dc02d4.html?from=search,共61页的文档,看完就差不多可以入 ...

  8. sgu179 SGU起航!

    //发现dfs除了搜索功能外的其他功能,他本身是一种序列,这个题恰是"先序"的下一个(合法范围内)序列! #include<iostream> #include< ...

  9. Python基础之 一 文件操作

    文件操作 流程: 1:打开文件,得到文件句柄并赋值给一个变量 2:通过句柄对文件进行操作 3:关闭文件 模式解释 r(读) , w(写) ,a(附加)r+(读写的读), w+(读写的写),a+(读附加 ...

  10. java基础语法4--封装,继承,多态

    学习路线: 未封装==>封装==>继承==>多态==>抽象类 首先还是那句话,万物皆对象,对象有行为和属性. 一:封装 1.封装的概念: 信息隐蔽和对象的属性及操作结合成一个独 ...