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(搜索)的更多相关文章
- SQLSERVER走起微信公众帐号已经开通搜狗微信搜索
SQLSERVER走起微信公众帐号已经开通搜狗微信搜索 请打开下面链接 http://weixin.sogou.com/gzh?openid=oIWsFt-hiIb_oYqQHaBMoNwRB2wM ...
- solr_架构案例【京东站内搜索】(附程序源代码)
注意事项:首先要保证部署solr服务的Tomcat容器和检索solr服务中数据的Tomcat容器,它们的端口号不能发生冲突,否则web程序是不可能运行起来的. 一:solr服务的端口号.我这里的sol ...
- SQLServer地址搜索性能优化例子
这是一个很久以前的例子,现在在整理资料时无意发现,就拿出来再改写分享. 1.需求 1.1 基本需求: 根据输入的地址关键字,搜索出完整的地址路径,耗时要控制在几十毫秒内. 1.2 数据库地址表结构和数 ...
- HTML5轻松实现搜索框提示文字点击消失---及placeholder颜色的设置
在做搜索框的时候无意间发现html5的input里有个placeholder属性能轻松实现提示文字点击消失功能,之前还傻傻的在用js来实现类似功能... 示例 <form action=&quo ...
- bzoj1079--记忆化搜索
题目大意:有n个木块排成一行,从左到右依次编号为1~n.你有k种颜色的油漆,其中第i种颜色的油漆足够涂ci个木块.所有油漆刚好足够涂满所有木块,即c1+c2+...+ck=n.相邻两个木块涂相同色显得 ...
- bzoj3208--记忆化搜索
题目大意: 花花山峰峦起伏,峰顶常年被雪,Memphis打算帮花花山风景区的人员开发一个滑雪项目. 我们可以把风景区看作一个n*n的地图,每个点有它的初始高度,滑雪只能从高处往低处滑[严格大于] ...
- Android中通过ActionBar为标题栏添加搜索以及分享视窗
在Android3.0之后,Google对UI导航设计上进行了一系列的改革,其中有一个非常好用的新功能就是引入的ActionBar,他用于取代3.0之前的标题栏,并提供更为丰富的导航效果.Action ...
- 一步步开发自己的博客 .NET版(5、Lucenne.Net 和 必应站内搜索)
前言 这次开发的博客主要功能或特点: 第一:可以兼容各终端,特别是手机端. 第二:到时会用到大量html5,炫啊. 第三:导入博客园的精华文章,并做分类.(不要封我) 第四:做 ...
- Go语言实战 - 我需要站内搜索
山坡网的用户抱怨"为什么搜索'二鬼子李富贵'找不到'二鬼子汉奸李富贵'?我用百度搜都能找到." 当时我就滴汗了,用户说的有道理,应该要能搜索到. 之前的方案很简单,用户输入的字串会 ...
随机推荐
- JQuery DOM 有关代码练习
//累加你选择的个数 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <hea ...
- JUnit4基础 使用JUnit4进行单元测试
JUnit 4全面引入了Annotation来执行我们编写的测试. 关于JUnit 3的使用可以参见:http://www.cnblogs.com/mengdd/archive/2013/03/26/ ...
- Java单元测试:@BeforeClass,@Before,@Test,@After,@AfterClass中的问题详解
在Junit4中还有的测试注解有: @BeforeClass ,@Before,@Test,@After,@AfterClass 1.其中:@BeforeClass,@AfterClass是Juni ...
- Good Teacher(模拟)
Good Teacher Time Limit:1000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Statu ...
- mysql 使用游标进行删除操作的存储过程
BEGIN DECLARE hprocessInstanceId bigint DEFAULT 0; -- 历史流程实例id DECLARE hprocessInstanceIdStart ...
- UIImage图片处理
#pragma mark - #pragma mark - 缩放处理 + (UIImage *)scaleImage:(UIImage *)image withScale:(float)scale { ...
- 9. KNN和Sparse构图
一.前言 图是一种重要的数据结构,本文主要表示图像的无向图.所谓无向图是指,图的节点间通过没有方向的边连接. 无向图的表示: 无向图G=<V,E>,其中: 1.V是非空集合,称为顶点集. ...
- MVC 数据列表显示插件大全
Jgrid 官网示例: http://www.trirand.net/demo/aspnet/mvc/jqgrid/ Code Project示例: http://www.codeproject.co ...
- (原)Eclipse的java中文件读写
1 在<uses-sdk…/>下面添加permission <uses-sdk android:minSdkVersion="16" android:target ...
- Tomcat 服务器的端口号的修改
在系统中找到Tomcat安装目录下的conf文件夹下的servlet.xml文件. (1)在servlet.xml文件中找到以下代码: <connector port="8080&qu ...