bzoj2768: [JLOI2010]冠军调查(双倍经验最小割)
2768: [JLOI2010]冠军调查
题目:传送门
题解:
双倍经验(1934)
代码:
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define qread(x) x=read()
using namespace std;
inline int read()
{
int f=,x=;char ch;
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return f*x;
}
struct node
{
int x,y,c,next,other;
}a[];int len,last[];
int n,m,st,ed;
void ins(int x,int y,int c)
{
int k1,k2;
k1=++len;
a[len].x=x;a[len].y=y;a[len].c=c;
a[len].next=last[x];last[x]=len; k2=++len;
a[len].x=y;a[len].y=x;a[len].c=;
a[len].next=last[y];last[y]=len; a[k1].other=k2;
a[k2].other=k1;
}
int list[],h[],head,tail;
bool bt_h()
{
memset(h,,sizeof(h));h[st]=;
list[]=st;head=;tail=;
while(head!=tail)
{
int x=list[head];
for(int k=last[x];k;k=a[k].next)
{
int y=a[k].y;
if(h[y]== && a[k].c>)
{
h[y]=h[x]+;
list[tail++]=y;
}
}
head++;
}
if(h[ed]>)return true;
return false;
}
int find_flow(int x,int flow)
{
if(x==ed)return flow;
int s=,t;
for(int k=last[x];k;k=a[k].next)
{
int y=a[k].y;
if(h[y]==h[x]+ && a[k].c> && s<flow)
{
s+=t=find_flow(y,min(a[k].c,flow-s));
a[k].c-=t;a[a[k].other].c+=t;
}
}
if(s==)h[x]=;
return s;
}
int main()
{
qread(n);qread(m);
len=;memset(last,,sizeof(last));
st=-;ed=st+;
for(int i=;i<=n;i++)
{
int x;qread(x);
if(x==)ins(st,i,);
else ins(i,ed,);
}
for(int i=;i<=m;i++)
{
int x,y;
qread(x);qread(y);
ins(x,y,);
ins(y,x,);
}
int ans=;
while(bt_h())ans+=find_flow(st,);
printf("%d\n",ans);
return ;
}
bzoj2768: [JLOI2010]冠军调查(双倍经验最小割)的更多相关文章
- [BZOJ2768][JLOI2010]冠军调查(最小割)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=2768 分析: 如果一个点i认为是0,则连一条S->i,如果认为是1,则i-> ...
- BZOJ2768 JLOI2012冠军调查(最小割)
容易想到网络流.将每个人拆成0和1两个点.若某人值为0的话则让源连向0,否则让1连向汇,流量为1.相互认识的人之间01各自连边.跑最小割即可. #include<iostream> #in ...
- BZOJ-2768: [JLOI2010]冠军调查(超级裸的最小割)
2768: [JLOI2010]冠军调查 Time Limit: 10 Sec Memory Limit: 128 MB Description 一年一度的欧洲足球冠军联赛已经进入了淘汰赛阶段.随着 ...
- BZOJ2768: [JLOI2010]冠军调查
2768: [JLOI2010]冠军调查 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 484 Solved: 332[Submit][Status ...
- BZOJ 2768 冠军调查(最小割)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2768 题意:给出一个无向图,每个点有一个值0或者1.现在重新设置每个点的值0或者1.设重 ...
- bzoj1934: [Shoi2007]Vote 善意的投票&&bzoj2768:[JLOI2010]冠军调查
get到新姿势,最小割=最大流,来个大佬的PPT 这道题的做法是将st和1的xpy连,0的xpy和ed连,xpy之间jy连双向边,然后呢答案就是最小割. #include<cstdio> ...
- 【BZOJ2768】[JLOI2010]冠军调查/【BZOJ1934】[Shoi2007]Vote 善意的投票 最小割
[BZOJ2768][JLOI2010]冠军调查 Description 一年一度的欧洲足球冠军联赛已经进入了淘汰赛阶段.随着卫冕冠军巴萨罗那的淘汰,英超劲旅切尔西成为了头号热门.新浪体育最近在吉林教 ...
- 【BZOJ-2768】冠军调查 最小割
2768: [JLOI2010]冠军调查 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 971 Solved: 661[Submit][Status ...
- BZOJ 2768: [JLOI2010]冠军调查 最小割
2768: [JLOI2010]冠军调查 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=2768 Description 一年一度的欧洲足 ...
随机推荐
- Struts2 的工作原理
Struts2 的工作原理: 1)client向server发出一个http请求.webserver对请求进行解析,假设在StrutsPrepareAndExecuteFilter的请求映射路径(在w ...
- remote debug
https://docs.microsoft.com/en-us/visualstudio/debugger/remote-debugging https://docs.microsoft.com/e ...
- hdoj--1087--Super Jumping! Jumping! Jumping!(贪心)
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- stackoverflow 加载特慢解决方案,配置 hosts 屏蔽速度慢的第三方 API
127.0.0.1 ajax.googleapis.com www.googletagservices.com www.gravatar.com 127.0.0.1 securepubads.g.do ...
- tp5页面跳转,空控制器空方法
namespace app\index\controller; use think\Controller; class Login extends Controller{ //显示html页面 pub ...
- redux原理
Redux实现原理 不同组件需要依赖同一个数据的时候,就需要状态提升至这些组件的根组件. redux是状态统一管理工具,需要使用它的原因是: 组件之间通信统一管理,方便代码维护. React中有一个特 ...
- QQ自动登录里的一些控件知识
在这个程序里面有个读取计算机指定文件的知识: private void button2_Click(object sender, EventArgs e) { openFileDialog1.Show ...
- 在IIS 10中注册自定义的IHttpModule
环境:Visual Studio 2015, IIS Express 10, ASP.NET 4.5 演示代码:http://files.cnblogs.com/files/joe-yang/Rewr ...
- 【摘录】JAVA内存管理-JVM垃圾收集机制
很多公司都有自己的JVM实现,被Oracle收购的sun公司开发的JVM实现名为HotSpot.这一实现是我们最常用到的. 还有哪些JVM实现呢?比较有名的有Oracle之前收购的BEA公司(就是以前 ...
- Java以流的方式将指定文件夹里的.txt文件全部复制到另一文件夹,并删除原文件夹中所有.txt文件
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.Fi ...