题面

因为$A$中只有奇偶性不同的人才能做朋友,所以A中只可能出0/1/2个人,分类讨论

然后$B$中求最大团,转成补图后正好是个二分图(不然就不用做了),求最大点独立集=总点数-最大匹配

我洛谷上交的时候建边的时候制杖了,成了$O(n^2m^2)$建边,还好数据水跑不满+网络流跑得快900ms救回来了,估计BZOJ肯定gg了,正确的做法是直接对B全部建然后走边的时候判一下

 #include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=,M=,inf=1e9;
int p[N],from[M],noww[M],goal[M],flw[M],flow[M];
int a[N],b[N],pp[N],ch[N],dep[N],que[N];
int T,n,m,s,t,fr,bk,q,t1,t2,cnt,ans;
vector<int> ve[N];
vector<int> ::iterator it;
bool Odd(int x){return x&;}
bool Even(int x){return !(x&);}
int Bitcount(int x)
{
int ret=;
while(x)
ret++,x-=x&-x;
return ret;
}
void Link(int f,int t,int v)
{
noww[++cnt]=p[f],p[f]=cnt,from[cnt]=f;
goal[cnt]=t,flw[cnt]=flow[cnt]=v;
noww[++cnt]=p[t],p[t]=cnt,from[cnt]=t;
goal[cnt]=f,flw[cnt]=flow[cnt]=;
}
bool Layering(int st,int ed)
{
for(int i=;i<=ed;i++)
pp[i]=p[i],dep[i]=-;
dep[st]=,que[fr=bk=]=st;
while(fr<=bk)
{
int tn=que[fr++];
for(int i=pp[tn];i;i=noww[i])
if(ch[from[i]]&&ch[goal[i]])
if(dep[goal[i]]==-&&flow[i])
dep[goal[i]]=dep[tn]+,que[++bk]=goal[i];
}
return ~dep[ed];
}
int Augmenting(int nd,int ed,int mn)
{
if(nd==ed||!mn) return mn;
int tmp=,tep=;
for(int i=pp[nd];i;i=noww[i])
if(ch[from[i]]&&ch[goal[i]])
{
pp[nd]=i;
if(dep[goal[i]]==dep[nd]+)
if(tep=Augmenting(goal[i],ed,min(mn,flow[i])))
{
flow[i]-=tep,mn-=tep;
flow[i^]+=tep,tmp+=tep;
if(!mn) break;
}
}
return tmp;
}
int Dinic_Maxflow(int st,int ed)
{
int ret=;
while(Layering(st,ed))
ret+=Augmenting(st,ed,inf);
return ret;
}
int main()
{
register int i,j,k;
scanf("%d",&T);
while(T--)
{
scanf("%d%d%d",&n,&m,&q),ans=;
for(i=;i<=n;i++) ve[i].clear();
for(i=;i<=n;i++) scanf("%d",&a[i]);
for(i=;i<=m;i++) scanf("%d",&b[i]);
for(i=;i<=q;i++)
scanf("%d%d",&t1,&t2),ve[t1].push_back(t2);
cnt=,s=m+,t=s+;
for(i=;i<=m+;i++) ch[i]=,p[i]=;
for(i=;i<=m;i++)
for(j=i+;j<=m;j++)
if(Odd(b[i]^b[j])&&Even(Bitcount(b[i]|b[j])))
Odd(b[i])?Link(i,j,):Link(j,i,);
for(i=;i<=m;i++)
Odd(b[i])?Link(s,i,):Link(i,t,);
ans=max(ans,m-Dinic_Maxflow(s,t));
for(i=;i<=n;i++)
{
int tmp=;
for(j=;j<=m;j++) ch[j]=;
for(j=;j<=cnt;j++) flow[j]=flw[j];
for(it=ve[i].begin();it!=ve[i].end();it++) tmp++,ch[*it]=;
ans=max(ans,tmp-Dinic_Maxflow(s,t)+);
}
for(i=;i<=n;i++)
for(k=i+;k<=n;k++)
if(Odd(a[i]^a[k]))
{
int tmp=;
for(j=;j<=m;j++) ch[j]=;
for(j=;j<=cnt;j++) flow[j]=flw[j];
for(it=ve[i].begin();it!=ve[i].end();it++) ch[*it]++;
for(it=ve[k].begin();it!=ve[k].end();it++) ch[*it]++;
for(j=;j<=m;j++) ch[j]==?tmp++,ch[j]=:ch[j]=;
ans=max(ans,tmp-Dinic_Maxflow(s,t)+);
}
printf("%d\n",ans);
}
return ;
}

解题:HEOI 2012 朋友圈的更多相关文章

  1. Leetcode547 朋友圈解题报告 (DFS

    题目描述: 班上有 N 名学生.其中有些人是朋友,有些则不是.他们的友谊具有是传递性.如果已知 A 是 B 的朋友,B 是 C 的朋友,那么我们可以认为 A 也是 C 的朋友.所谓的朋友圈,是指所有朋 ...

  2. C++之路进阶——codevs2366(朋友圈)

    2366 朋友圈 2012年省队选拔赛河北  时间限制: 10 s  空间限制: 256000 KB  题目等级 : 大师 Master     题目描述 Description 在很久很久以前,曾经 ...

  3. [LeetCode] Friend Circles 朋友圈

    There are N students in a class. Some of them are friends, while some are not. Their friendship is t ...

  4. LeetCode 547 朋友圈

    题目: 班上有 N 名学生.其中有些人是朋友,有些则不是.他们的友谊具有是传递性.如果已知 A 是 B 的朋友,B 是 C 的朋友,那么我们可以认为 A 也是 C 的朋友.所谓的朋友圈,是指所有朋友的 ...

  5. Leetcode之深度优先搜索(DFS)专题-547. 朋友圈(Friend Circles)

    Leetcode之深度优先搜索(DFS)专题-547. 朋友圈(Friend Circles) 深度优先搜索的解题详细介绍,点击 班上有 N 名学生.其中有些人是朋友,有些则不是.他们的友谊具有是传递 ...

  6. [LeetCode] 547. Friend Circles 朋友圈

    There are N students in a class. Some of them are friends, while some are not. Their friendship is t ...

  7. QQ空间/朋友圈类界面的搭建

    类似于QQ空间的布局主要是在说说信息.点赞.回复三大部分的自适应布局上. 当我们需要搭建类似QQ空间.微信朋友圈的界面的时候,可做如下操作: 创建一个对应的model类: 创建一个对应model类的f ...

  8. Python微信-- 分享接口(分享到朋友圈、朋友、空间)

    生成JS-SDK权限验证的签名 获取signature(签名)首先要获得 1.#获得jsapi_ticket 2.#获取当前页面的url #获取当前页面的url url="{}://{}{} ...

  9. Apple Watch版微信来了 收发微信刷朋友圈不在话下

    昨晚果粉守了一夜的Apple Watch发布会,意料中的惊喜不少,最让人兴奋的是微信成为首批支持的应用.是的,在全球拥有4.68亿月活跃用户的微信怎么可能不第一时间入驻呢?之前我们就有聊过Apple ...

随机推荐

  1. 【来龙去脉系列】AutoMapper一款自动映射框架

    前言 通常在一个应用程序中,我们开发人员会在两个不同的类型对象之间传输数据,通常我们会用DTOs(数据传输对象),View Models(视图模型),或者直接是一些从一个service或者Web AP ...

  2. EZ 2018 03 30 NOIP2018 模拟赛(六)

    链接:http://211.140.156.254:2333/contest/67 转眼间上次加回来的Rating又掉完了. 这次不知为何特别水,T1想了一段时间没想出来弃了,导致后面心态炸了. T2 ...

  3. LCA的一些算法

    LCA,就是求树上任意两点的最近公共祖先 (本题图片与代码均为Luogu3379) 方法我好像讲过一个,这次把主要的三个一起讲一讲 <1> 倍增(O(n log n)) 我们先考虑最基本的 ...

  4. 汇编  cdecl 函数调用约定,stdcall 函数调用约定

    知识点:  cdecl 函数调用约定  stdcall 函数调用约定  CALL堆栈平衡 配置属性--> c/c++ -->高级-->调用约定 一.cdecl调用约定 VC++ ...

  5. maven 相关问题

    maven 这里要更新完 不一定非要clean install  那个出问题了再弄,一般刷新一下maven仓库就行了,最好还是用自己配置的maven,不容易出问题

  6. Jmeter(九)_获取JDBC响应做接口关联

    在之前的文章-参数关联中,留个一个小尾巴,这里补充一下 http://www.cnblogs.com/Zfc-Cjk/p/8295495.html 1:从sql表中将需要取的数据查出来 2:我们需要把 ...

  7. App云测试服务对比

    前言: 我们都知道在测试移动app时最耗时的是在各种测试设备进行测试, 因为不论是安卓还是iOS都已经碎片化了.而云测试看似是解决这一问题的有效途径.因此选择哪种云测试平台来协助测试人员进行各种测试就 ...

  8. React Native 'config.h' file not found 问题、 'glog/logging.h' file not found 问题、configure: error: C compiler cannot create executables问题解决过程记录

    1.在github 上面 git clone 一个RN 项目代码,npm install (yarn)后,准备运行iOS工程,发现'config.h' file not found ,恶心!!! 百度 ...

  9. 《Linux内核设计与实现》第五章读书笔记

    第五章  系统调用 5.1与内核通信 1. 系统调用 让应用程序受限的访问硬件设备 提供创建新进程并与已有进程通信的机制 提供申请操作系统其他资源能力是用户空间进程和硬件设备之间的中间层 2. 系统调 ...

  10. 将搬家至CSDN

    emmm,感觉没利用好博客,自己也弄了一个github上面的hexo博客https://clarkkun.github.io/,但是死活传不上去内容,尴尬 ̄□ ̄||,三个博客齐头并进吧