2768: [JLOI2010]冠军调查/1934: [Shoi2007]Vote 善意的投票
来源:互联网 发布:网络推手的联系方式 编辑:程序博客网 时间:2024/05/29 10:36
题目链接
题目大意:给出一个无向图,每个点有一个值0或者1。现在重新设置每个点的值0或者1。设重新设置后的点与原来的点有x个点的值不一样;重新设置后有y条边(u,v)使得u和v的值不同。最小化x+y
题解:集合划分模型
我的收获:基本模型
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std; const int M=305;#define INF 0x3f3f3f3f int n,m,st,ed,t;int col[M],head[M],last[M],d[M],num[M];bool Exit; struct edge{int to,c,nex;}e[M*M*2]; void add(int u,int v,int w){e[t]=(edge){v,w,head[u]};last[u]=head[u]=t++;}void insert(int x,int y,int z){add(x,y,z),add(y,x,0);}; int dfs(int x,int in){ if(x==ed) return in; int ans=0,f; for(int i=last[x];i!=-1;last[x]=i=e[i].nex) { int v=e[i].to; if(e[i].c&&d[v]==d[x]-1){ f=dfs(v,min(in-ans,e[i].c)); ans+=f; e[i].c-=f; e[i^1].c+=f; if(Exit||ans==in) return ans; } } if(--num[d[x]]==0) Exit=1; d[x]++,num[d[x]]++,last[x]=head[x]; return ans;} int ISAP(){ Exit=0;int flow=0; while(!Exit) flow+=dfs(st,INF); return flow;} void work(){ cout<<ISAP()<<endl;} void init(){ cin>>n>>m; st=0,ed=n+1,num[0]=ed+1; memset(head,-1,sizeof(head)); memset(last,-1,sizeof(last)); for(int i=1;i<=n;i++){ scanf("%d",&col[i]); if(col[i]) insert(st,i,1); else insert(i,ed,1); } int x,y; for(int i=1;i<=m;i++){ scanf("%d%d",&x,&y); insert(x,y,1),insert(y,x,1);//为了避免讨论 } } int main(){ init(); work(); return 0;}
阅读全文
0 0
- 2768: [JLOI2010]冠军调查/1934: [Shoi2007]Vote 善意的投票
- BZOJ 1934: [Shoi2007]Vote 善意的投票
- bzoj 1934: [Shoi2007]Vote 善意的投票
- 【BZOJ 1934】 [Shoi2007]Vote 善意的投票
- BZOJ-1934-Vote善意的投票-SHOI2007
- 【BZOJ 1934】 [Shoi2007]Vote 善意的投票
- BZOJ 1934 [Shoi2007]Vote 善意的投票
- 1934: [Shoi2007]Vote 善意的投票
- 1934: [Shoi2007]Vote 善意的投票
- BZOJ 1934: [Shoi2007]Vote 善意的投票
- 1934: [Shoi2007]Vote 善意的投票 (网络流)
- BZOJ 1934([Shoi2007]Vote 善意的投票-最小割)
- bzoj 1934: [Shoi2007]Vote 善意的投票(最小割)
- 【bzoj 1934】[Shoi2007]Vote 善意的投票 最小割
- 【bzoj1934】 [Shoi2007]Vote 善意的投票
- bzoj1934【shoi2007】Vote善意的投票
- [bzoj1934]: [Shoi2007]Vote 善意的投票
- bzoj1934: [Shoi2007]Vote 善意的投票
- 如何理解 Hibernate的延迟加载机制?延迟加载与Session关闭的矛盾如何处理?
- 机器学习&数据挖掘笔记_16(常见面试之机器学习算法思想简单梳理)
- 【集训Day2 哈希表】【NHOI2015】【Luogu P2421】差
- 从ios角度Cordova类图及初始化和互调用流程
- Power Strings||POJ2406
- 2768: [JLOI2010]冠军调查/1934: [Shoi2007]Vote 善意的投票
- ZOJ 3953-贪心
- Android 使用SpannableString设置金钱文本显示
- C语言位运算符:与、或、异或、取反、左移和右移
- Java之API
- automaticallyAdjustsScrollViewInsets解析
- eclipse maven 导出项目依赖的jar包
- strcpy,strcmp,strstr,strcat,memcpy,memmove的模拟实现
- c++ primer plus阅读笔记10---定位new using namespace