题面

因为$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. Python3入门(三)——Python基础语法

    一.基本语法 1.行和缩进 Python中,不使用括号来表示代码的类和函数定义块或流程控制. 代码块是由行缩进,缩进位的数目是可变的,但是在块中的所有语句必须缩进相同的量. 如下所示: a = 100 ...

  2. OFS环境,删除Resource 时出现错误失败,应该如何继续

    From the Windows failover cluster manager,select the group listener, stop it, and delete it.  Do the ...

  3. python装饰器 练习

    用类作为装饰器 练习一 最初代码 class bol(object): def __init__(self, func): self.func = func def __call__(self): r ...

  4. [Deep-Learning-with-Python]基于Keras的房价预测

    预测房价:回归问题 回归问题预测结果为连续值,而不是离散的类别. 波士顿房价数据集 通过20世纪70年代波士顿郊区房价数据集,预测平均房价:数据集的特征包括犯罪率.税率等信息.数据集只有506条记录, ...

  5. Node总结 模块机制

    1. Node中的模块分为两类.一个是node提供的模块,称为核心模块,如http, fs, path:另一类是用户编写的模块,称为文件模块. 2. require()方法接收一个标识符进行模块查找. ...

  6. Invitation Cards POJ-1511 (spfa)

    题目链接:Invitation Cards 题意: 给出一张有向图,现在要求从1到其他所有的结点的最小路径和与从所有其他结点到1的最小路径和之和. 题解: 求最小路径可以用SPFA来求解.从1到其他结 ...

  7. Markdown打造高逼格博客

    这里首先假设读者你已经掌握了Markdown与GitHub的基本用法 如果不会, 请先自行百度或Google, 我目前还没写Markdown与GitHub的教程 看云只是一个推荐, 可以认为协助生成格 ...

  8. More Effective C++ Item14:明智运用exception specifications

    使用exception specifications你必须非常仔细去确保,函数调用的子函数.注册的回调函数不会违背约定.而设计模板内部的异常更难确保. 设计回调机制的时候,如果调用方规定了不抛出异常, ...

  9. kubernetes部署mysql

    第一章 部署K8S集群 https://www.cnblogs.com/zoulixiang/p/9504324.html 第二章 1.新建mysql-rc.yaml vi mysql-rc.yaml ...

  10. net面试宝典

    ASP.NET常见面试题及答案 1. 简述 private. protected. public. internal 修饰符的访问权限. 答 . private : 私有成员, 在类的内部才可以访问. ...