Back to Underworld

Time Limit:4000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu

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

题解:两拨人打架,问最每队最大的可能人数是多少;搜索下。。。

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
using namespace std;
const int INF = 0x3f3f3f3f;
#define mem(x, y) memset(x, y, sizeof(x))
typedef long long LL;
void SI(int &x){scanf("%d", &x);}
void SI(LL &x){scanf("%lld", &x);}
const int MAXN = 1e5 + ;
int vis[MAXN], usd[MAXN];
int sum1, sum2;
vector<int>vec[MAXN];
void dfs(int i, int cur){
if(cur)sum1++;
else sum2++;
// vis[i] = 1;
for(int j = ; j < vec[i].size(); j++){
int v = vec[i][j];
if(vis[v])continue;
vis[v] = ;
dfs(v, cur ^ );
}
}
int main(){
int T,kase = , n;
scanf("%d", &T);
while(T--){
scanf("%d", &n);
int x, y, tp = ;
for(int i = ; i <= MAXN; i++){
vis[i] = ;
usd[i] = ;
vec[i].clear();
}
for(int i = ; i < n; i++){
scanf("%d%d", &x, &y);
vec[x].push_back(y);
vec[y].push_back(x);
usd[x] = usd[y] = ;
tp = max(tp, x);
tp = max(tp, y);
}
int ans = ;
//printf("tp = %d\n", tp);
for(int i = ; i <= tp; i++){
if(vis[i] || !usd[i])continue;
sum1 = sum2 = ;
vis[i] = ;
dfs(i, );
// printf("%d %d %d \n", sum1,sum2,i);
ans += max(sum1, sum2);
}
printf("Case %d: %d\n", ++kase, ans);
}
return ;
}
 

Back to Underworld(搜索)的更多相关文章

  1. SQLSERVER走起微信公众帐号已经开通搜狗微信搜索

    SQLSERVER走起微信公众帐号已经开通搜狗微信搜索 请打开下面链接 http://weixin.sogou.com/gzh?openid=oIWsFt-hiIb_oYqQHaBMoNwRB2wM ...

  2. solr_架构案例【京东站内搜索】(附程序源代码)

    注意事项:首先要保证部署solr服务的Tomcat容器和检索solr服务中数据的Tomcat容器,它们的端口号不能发生冲突,否则web程序是不可能运行起来的. 一:solr服务的端口号.我这里的sol ...

  3. SQLServer地址搜索性能优化例子

    这是一个很久以前的例子,现在在整理资料时无意发现,就拿出来再改写分享. 1.需求 1.1 基本需求: 根据输入的地址关键字,搜索出完整的地址路径,耗时要控制在几十毫秒内. 1.2 数据库地址表结构和数 ...

  4. HTML5轻松实现搜索框提示文字点击消失---及placeholder颜色的设置

    在做搜索框的时候无意间发现html5的input里有个placeholder属性能轻松实现提示文字点击消失功能,之前还傻傻的在用js来实现类似功能... 示例 <form action=&quo ...

  5. bzoj1079--记忆化搜索

    题目大意:有n个木块排成一行,从左到右依次编号为1~n.你有k种颜色的油漆,其中第i种颜色的油漆足够涂ci个木块.所有油漆刚好足够涂满所有木块,即c1+c2+...+ck=n.相邻两个木块涂相同色显得 ...

  6. bzoj3208--记忆化搜索

    题目大意: 花花山峰峦起伏,峰顶常年被雪,Memphis打算帮花花山风景区的人员开发一个滑雪项目.    我们可以把风景区看作一个n*n的地图,每个点有它的初始高度,滑雪只能从高处往低处滑[严格大于] ...

  7. Android中通过ActionBar为标题栏添加搜索以及分享视窗

    在Android3.0之后,Google对UI导航设计上进行了一系列的改革,其中有一个非常好用的新功能就是引入的ActionBar,他用于取代3.0之前的标题栏,并提供更为丰富的导航效果.Action ...

  8. 一步步开发自己的博客 .NET版(5、Lucenne.Net 和 必应站内搜索)

    前言 这次开发的博客主要功能或特点:    第一:可以兼容各终端,特别是手机端.    第二:到时会用到大量html5,炫啊.    第三:导入博客园的精华文章,并做分类.(不要封我)    第四:做 ...

  9. Go语言实战 - 我需要站内搜索

    山坡网的用户抱怨"为什么搜索'二鬼子李富贵'找不到'二鬼子汉奸李富贵'?我用百度搜都能找到." 当时我就滴汗了,用户说的有道理,应该要能搜索到. 之前的方案很简单,用户输入的字串会 ...

随机推荐

  1. python list 按长度分段

    def changes(a,b): #list 分段函数,a:数据[(1),(2)]b:长度 for i in xrange(0,len(a),b): yield  a[i:i+b] for i in ...

  2. XNOR-Net ImageNet Classification Using Binary Convolutional Neural Networks

    转载请注明出处: http://www.cnblogs.com/sysuzyq/p/6245186.html by 少侠阿朱

  3. Guice 学习(六)使用Provider注入服务( Provider Inject Service)

    1.定义接口 package com.guice.providerInject; import com.google.inject.ProvidedBy; public interface Servi ...

  4. C++ 报错 R6030 CRT not initialized

    昨天,在写一个算法的时候,报错R6030 CRT not initialized. 认真检查发现,是出了比较低级的错误. 一. 会出错的代码,编译的时候不会报错,执行过程中报R6030 CRT not ...

  5. 数据库的四种语言(DDL、DML、DCL、TCL)

    1.DDL (Data Definition Language )数据库定义语言 statements are used to define the database structure or sch ...

  6. Docker网络管理-外部访问容器

    注意:这里使用的方法是端口映射,需要说明的是端口映射是在容器启动的时候才能完成端口映射的. 1,搭建1个web服务器,让外部机器访问. docker run -itd centos /bin/bash ...

  7. nginx搭建flv、mp4流媒体服务

    1.安装pcre-8.33.tar.bz2 #tar -xvf 1.pcre-8.33.tar.bz2 #cd pcre-8.33/ #./configure #make && mak ...

  8. QQ中未读气泡拖拽消失的实现(参照一位年轻牛B的博主的思路自己实现了一下)

    原文链接:http://kittenyang.com/drawablebubble/,博主年轻却很有思想.相仿的年纪,很佩服他! 首先分析拖拽时的图,大圆.不规则的图(实际上时有规律的不然也画不出来, ...

  9. UIScrollView 代理方法

    在使用UIScrollView和它的子类UITableView时,有时需要在不同操作状态下,做不同的响应. 如何截获这些状态,如正在滚动,滚动停止等,使用UIScrollViewDelegate_Pr ...

  10. qq去广告

    首先呢,在文件资源管理器中选择查看"隐藏的项目"或"显示隐藏的文件.文件夹和驱动器"(入口不一样,选择显示隐藏文件的方式也不一样),随后进入 C:\Users\ ...