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]冠军调查(双倍经验最小割)的更多相关文章

  1. [BZOJ2768][JLOI2010]冠军调查(最小割)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=2768 分析: 如果一个点i认为是0,则连一条S->i,如果认为是1,则i-> ...

  2. BZOJ2768 JLOI2012冠军调查(最小割)

    容易想到网络流.将每个人拆成0和1两个点.若某人值为0的话则让源连向0,否则让1连向汇,流量为1.相互认识的人之间01各自连边.跑最小割即可. #include<iostream> #in ...

  3. BZOJ-2768: [JLOI2010]冠军调查(超级裸的最小割)

    2768: [JLOI2010]冠军调查 Time Limit: 10 Sec  Memory Limit: 128 MB Description 一年一度的欧洲足球冠军联赛已经进入了淘汰赛阶段.随着 ...

  4. BZOJ2768: [JLOI2010]冠军调查

    2768: [JLOI2010]冠军调查 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 484  Solved: 332[Submit][Status ...

  5. BZOJ 2768 冠军调查(最小割)

    题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2768 题意:给出一个无向图,每个点有一个值0或者1.现在重新设置每个点的值0或者1.设重 ...

  6. bzoj1934: [Shoi2007]Vote 善意的投票&&bzoj2768:[JLOI2010]冠军调查

    get到新姿势,最小割=最大流,来个大佬的PPT 这道题的做法是将st和1的xpy连,0的xpy和ed连,xpy之间jy连双向边,然后呢答案就是最小割. #include<cstdio> ...

  7. 【BZOJ2768】[JLOI2010]冠军调查/【BZOJ1934】[Shoi2007]Vote 善意的投票 最小割

    [BZOJ2768][JLOI2010]冠军调查 Description 一年一度的欧洲足球冠军联赛已经进入了淘汰赛阶段.随着卫冕冠军巴萨罗那的淘汰,英超劲旅切尔西成为了头号热门.新浪体育最近在吉林教 ...

  8. 【BZOJ-2768】冠军调查 最小割

    2768: [JLOI2010]冠军调查 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 971  Solved: 661[Submit][Status ...

  9. BZOJ 2768: [JLOI2010]冠军调查 最小割

    2768: [JLOI2010]冠军调查 题目连接: http://www.lydsy.com/JudgeOnline/problem.php?id=2768 Description 一年一度的欧洲足 ...

随机推荐

  1. cocos2d-x之浅析Hello World

    ***************************************转载请注明出处:http://blog.csdn.net/lttree************************** ...

  2. 【POJ 2182】Lost Cows

    [题目链接] http://poj.org/problem?id=2182 [算法] 树状数组 + 二分 [代码] #include <algorithm> #include <bi ...

  3. org/eclipse/jetty/util/component/Container$Listener

    转自:https://blog.csdn.net/husheng8891/article/details/10200965?locationNum=9&fps=1 项目Demo开发的时候,发布 ...

  4. Java中的作用域有哪些

    在Java语言中,变量的类型主要有3种:成员变量.静态变量和局部变量 首先说静态变量跟局部变量 静态变量不依赖于特定的实例,而是被所有实例共享,也就是说,只要一个类被加载,JVM就会给类的静态变量分配 ...

  5. Core Java(五)

    类和对象&方法 ——类的定义 现实世界的事物 属性:人的身高,体重等 行为:人可以学习,吃饭等 Java中用class描述事物也是如此 成员变量:就是事物的属性 成员方法:就是事物的行为    ...

  6. iOS11访问相册权限变更问题

    手机升到iOS 11后  发现之前正常的图片保存功能无法正常使用  会闪退 经测试发现应该是权限没有开启的原因  但是NSPhotoLibraryUsageDescription已经写入plist   ...

  7. python爬虫:爬取医药数据库drugbank

    这个是帮朋友做的,难点就是他们有一个反爬虫机制,用request一直不行,后面我就用selenium直接把网页copy下来,然后再来解析本地的html文件,就木有问题啦. 现在看来,写得有点傻,多包涵 ...

  8. 使用 Object.create实现js 继承

    二.Object.create实现继承 本文将来学习第七种继承方式Object.create()方法来实现继承,关于此方法的详细描述,请戳这里.下面来通过几个实例来学习该方法的使用: var Pare ...

  9. Lost Cows POJ - 2182 二分 + 树状数组

    Code: #include<cstdio> #include<stack> #include<cstring> #include<algorithm> ...

  10. 并发编程——全局解释器锁GIL

    1.全局解释器锁GIL GIL其实就是一把互斥锁(牺牲了效率但是保证了数据的安全). 线程是执行单位,但是不能直接运行,需要先拿到python解释器解释之后才能被cpu执行 同一时刻同一个进程内多个线 ...