cogs 2620. [HEOI2012]朋友圈
/*70分 被卡T*/
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int a[],b[],na,nb,m,head[],num;
int T1,T2,ban[],Link[],vis[],tim[],T;
bool map[][];
struct node{int to,pre;}e[];
void Insert(int from,int to){
e[++num].to=to;
e[num].pre=head[from];
head[from]=num;
}
int count(int x){
int res=;
while(x){
res+=x&;
x>>=;
}
return res;
}
bool find(int x){
if(ban[x]==T1)return ;
for(int i=head[x];i;i=e[i].pre){
int to=e[i].to;
if((ban[to]!=T1)&&(vis[to]!=T2)){
vis[to]=T2;
if(tim[to]!=T1||!Link[to]||find(Link[to])){
tim[to]=T1;
Link[to]=x;
return ;
}
}
}
return ;
}
int mis(int x=,int y=){
T1++;int res=;
for(int i=;i<=nb;i++)
if(map[x][i]||map[y][i])ban[i]=T1,res++;
for(int i=;i<=nb;i++)
if(b[i]&){
T2++;
if(find(i))res++;
}
return nb-res;
}
int main(){
freopen("friends.in","r",stdin);freopen("friends.out","w",stdout);
scanf("%d",&T);
while(T--){
memset(map,,sizeof(map));
memset(head,,sizeof(head));
memset(Link,,sizeof(Link));
memset(ban,,sizeof(ban));
memset(tim,,sizeof(tim));
memset(vis,,sizeof(vis));
num=;T1=;T2=;
scanf("%d%d%d",&na,&nb,&m);
for(int i=;i<=na;i++)scanf("%d",&a[i]);
for(int i=;i<=nb;i++)scanf("%d",&b[i]);
int x,y;
for(int i=;i<=m;i++){
scanf("%d%d",&x,&y);
map[x][y]=;
}
for(int i=;i<=nb;i++)
for(int j=i;j<=nb;j++){
if(((b[i]^b[j])%==)&&(count(b[i]|b[j])%==))
Insert(i,j),Insert(j,i);
}
for(int i=;i<=nb;i++)map[][i]=;
int ans=mis();
for(int i=;i<=na;i++)ans=max(ans,mis(i)+);
for(int i=;i<=na;i++)
for(int j=;j<=na;j++)
if((a[i]^a[j])%==)ans=max(ans,mis(i,j)+);
printf("%d\n",ans);
}
return ;
}
cogs 2620. [HEOI2012]朋友圈的更多相关文章
- bzoj 2744: [HEOI2012]朋友圈 二分图匹配
2744: [HEOI2012]朋友圈 Time Limit: 30 Sec Memory Limit: 128 MBSubmit: 612 Solved: 174[Submit][Status] ...
- 【BZOJ 2744】 2744: [HEOI2012]朋友圈 (最大团,二分图匹配,构图)
2744: [HEOI2012]朋友圈 Description 在很久很久以前,曾经有两个国家和睦相处,无忧无虑的生活着.一年一度的评比大会开始了,作为和平的两国,一个朋友圈数量最多的永远都是最值得他 ...
- 【BZOJ 2744 】[HEOI2012]朋友圈
Description 在很久很久以前,曾经有两个国家和睦相处,无忧无虑的生活着.一年一度的评比大会开始了,作为和平的两国,一个朋友圈数量最多的永远都是最值得他人的尊敬,所以现在就是需要你求朋友圈的最 ...
- BZOJ2744:[HEOI2012]朋友圈(最大团,乱搞)
Description 在很久很久以前,曾经有两个国家和睦相处,无忧无虑的生活着.一年一度的评比大会开始了,作为和平的两国,一个朋友圈数量最多的永远都是最值得他人的尊敬,所以现在就是需要你求朋友圈的最 ...
- 【刷题】BZOJ 2744 [HEOI2012]朋友圈
Description 在很久很久以前,曾经有两个国家和睦相处,无忧无虑的生活着.一年一度的评比大会开始了,作为和平的两国,一个朋友圈数量最多的永远都是最值得他人的尊敬,所以现在就是需要你求朋友圈的最 ...
- luogu P2423 [HEOI2012]朋友圈 (最大团)
在很久很久以前,曾经有两个国家和睦相处,无忧无虑的生活着. 一年一度的评比大会开始了,作为和平的两国,一个朋友圈数量最多的永远都是最值得他人的尊敬,所以现在就是需要你求朋友圈的最大数目.两个国家看成是 ...
- 【二分图】HEOI2012 朋友圈
题目内容 洛谷链接 在很久很久以前,曾经有两个国家和睦相处,无忧无虑的生活着. 一年一度的评比大会开始了,作为和平的两国,一个朋友圈数量最多的永远都是最值得他人的尊敬,所以现在就是需要你求朋友圈的最大 ...
- [HEOI2012]朋友圈
题目 我们发现我们要求的是一个最大团问题,众所周知这是一个\(NP\)难问题,除了爆搜没有什么别的方法,但是这道题我们可以根据图的特殊性质入手 我们如果把\(B\)国的人分成奇数和偶数两类,就会发现奇 ...
- bzoj 2744: [HEOI2012]朋友圈
#include<cstdio> #include<iostream> #define M 3010 using namespace std; ],u[M*M>>] ...
随机推荐
- C++(五)— 控制保留小数位数
1.C++中输出指定保留的小数位数. 这里还要注意,每次输出只要设置一次就行了,因为这两个的作用范围是后续对象,而不是仅对后一个对象起作用. #include<iostream> #inc ...
- django admin扩展user表password验证及set_password
一般如果扩展了django user内置表,在admin后台创建新用户的时候密码将会变成明文,故而导致登录不成功.所以我们在admin.py可以通过form自定义进行对password进行操作,可以双 ...
- Redis-benchmark使用总结
Redis-benchmark为Redis性能测试工具. 指令说明: Usage: redis-benchmark [-h <host>] [-p <port>] [-c &l ...
- JavaUtil_09_email_使用 commons-email 发送邮件
二.参考资料 1.[commons]邮件发送工具——commons-email
- linux命令学习笔记(20):find命令之exec
find是我们很常用的一个Linux命令,但是我们一般查找出来的并不仅仅是看看而已,还会有进一步的操作, 这个时候exec的作用就显现出来了. exec解释: -exec 参数后面跟的是command ...
- stl_heap.h
stl_heap.h // Filename: stl_heap.h // Comment By: 凝霜 // E-mail: mdl2009@vip.qq.com // Blog: http://b ...
- TYVJ P1728 普通平衡树
P1728 普通平衡树 时间: 1000ms / 空间: 131072KiB / Java类名: Main 背景 此为平衡树系列第一道:普通平衡树 描述 您需要写一种数据结构(可参考题目标题),来维护 ...
- HDU1370Biorhythms(中国剩余定理||暴力)
Some people believe that there are three cycles in a person's life that start the day he or she is b ...
- hdu 3998 Sequence
There is a sequence X (i.e. x[1], x[2], ..., x[n]). We define increasing subsequence of X as x[i1], ...
- ACM学习历程—FZU2148 Moon Game(计算几何)
Moon Game Description Fat brother and Maze are playing a kind of special (hentai) game in the clearl ...