网络流/最小割


  我不会告诉你这题跟 BZOJ 1934 是一模一样的……包括数据范围……

 /**************************************************************
Problem: 2768
User: Tunix
Language: C++
Result: Accepted
Time:32 ms
Memory:4408 kb
****************************************************************/ //BZOJ 2768
#include<vector>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;++i)
#define F(i,j,n) for(int i=j;i<=n;++i)
#define D(i,j,n) for(int i=j;i>=n;--i)
#define pb push_back
using namespace std;
inline int getint(){
int v=,sign=; char ch=getchar();
while(ch<''||ch>''){ if (ch=='-') sign=-; ch=getchar();}
while(ch>=''&&ch<=''){ v=v*+ch-''; ch=getchar();}
return v*sign;
}
const int N=,M=,INF=~0u>>;
typedef long long LL;
/******************tamplate*********************/
int n,m;
struct edge{
int from,to,v;
};
inline int pack(int i,int j){return (i-)*m+j;}
struct Net{
edge E[M];
int head[N],next[M],cnt;
void add(int x,int y,int v){
E[++cnt]=(edge){x,y,v};
next[cnt]=head[x]; head[x]=cnt;
E[++cnt]=(edge){y,x,};
next[cnt]=head[y]; head[y]=cnt;
}
int s,t,cur[N],d[N],Q[N];
void init(){
n=getint();m=getint();
cnt=;
s=; t=n+;
F(i,,n)
if (getint()) add(s,i,);
else add(i,t,);
int x,y;
F(i,,m){
x=getint(); y=getint();
add(x,y,);
add(y,x,);
}
}
bool mklevel(){
memset(d,-,sizeof d);
d[s]=;
int l=,r=-;
Q[++r]=s;
while(l<=r){
int x=Q[l++];
for(int i=head[x];i;i=next[i])
if (d[E[i].to]==- && E[i].v){
d[E[i].to]=d[x]+;
Q[++r]=E[i].to;
}
}
return d[t]!=-;
}
int dfs(int x,int a){
if (x==t||a==) return a;
int flow=;
for(int &i=cur[x];i && flow<a;i=next[i])
if (d[E[i].to]==d[x]+ && E[i].v){
int f=dfs(E[i].to,min(a-flow,E[i].v));
E[i].v-=f;
E[i^].v+=f;
flow+=f;
}
if (!flow) d[x]=-;
return flow;
}
int Dinic(){
int flow=;
while(mklevel()){
F(i,s,t) cur[i]=head[i];
flow+=dfs(s,INF);
}
return flow;
}
}G1;
int main(){
#ifndef ONLINE_JUDGE
freopen("2768.in","r",stdin);
freopen("2768.out","w",stdout);
#endif
G1.init();
printf("%d\n",G1.Dinic());
return ;
}

【BZOJ】【2768】【JLOI2010】冠军调查的更多相关文章

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

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

  2. bzoj 2768: [JLOI2010]冠军调查

    #include<cstdio> #include<iostream> #define M 100000 #include<cstring> using names ...

  3. 2768: [JLOI2010]冠军调查( 最小割 )

    最小割... 怎么乱搞都可以 -------------------------------------------------------------------------------- #inc ...

  4. BZOJ2768: [JLOI2010]冠军调查

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

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

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

  6. bzoj2768: [JLOI2010]冠军调查(双倍经验最小割)

    2768: [JLOI2010]冠军调查 题目:传送门 题解: 双倍经验(1934) 代码: #include<cstdio> #include<cstring> #inclu ...

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

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

  8. P2057 [SHOI2007]善意的投票 / [JLOI2010]冠军调查

    P2057 [SHOI2007]善意的投票 / [JLOI2010]冠军调查 拿来练网络流的qwq 思路:如果i不同意,连边(i,t,1),否则连边(s,i,1).好朋友x,y间连边(x,y,1)(y ...

  9. [JLOI2010]冠军调查 BZOJ2768 最小割

    题目描述 一年一度的欧洲足球冠军联赛已经进入了淘汰赛阶段.随着卫冕冠军巴萨罗那的淘汰,英超劲旅切尔西成为了头号热门. 新浪体育最近在吉林教育学院进行了一次大规模的调查,调查的内容就是关于切尔西能否在今 ...

  10. 【bzoj2768/bzoj1934】[JLOI2010]冠军调查/[Shoi2007]Vote 善意的投票 最小割

    bzoj2768 题目描述 一年一度的欧洲足球冠军联赛已经进入了淘汰赛阶段.随着卫冕冠军巴萨罗那的淘汰,英超劲旅切尔西成为了头号热门.新浪体育最近在吉林教育学院进行了一次大规模的调查,调查的内容就是关 ...

随机推荐

  1. php 图片调整大小 封装类【转载】

    <?php class ImageResize { private $image; private $img_des; private $image_type; private $permiss ...

  2. Java Executors(线程池)

    Sun在Java5中,对Java线程的类库做了大量的扩展,其中线程池就是Java5的新特征之一,除了线程池之外,还有很多多线程相关的内容,为多线程的编程带来了极大便利.为了编写高效稳定可靠的多线程程序 ...

  3. 分布式PostGIS系列【2】——pgpool-II

    一.pgpool-II简介 二.pgpool-II安装与配置 三.分布式Postgis性能测试

  4. Git tricks: Unstaging files

    NOTE: Following content is directly reprinted from http://andrewberls.com/blog/post/git-tricks-unsta ...

  5. java 设计模式之单例模式

    -------Success is getting what you want, happiness is wanting what you get. java设计模式之单例模式(Singleton) ...

  6. 好书推荐:《Game Programming Patterns》

    在线阅读点这里: http://gameprogrammingpatterns.com/contents.html 这是一个总结讨论和反思游戏客户端game play开发常用设计模式的书. 游戏开发和 ...

  7. insertorupdate

    MERGE INTO  运用的心得 最近完成一个功能,就是往表里插入数据,以party_id 和prod_id为联合主键,存在的更新,不存在的插入, ORACLE 10g 后可以试用MERGE INT ...

  8. python自定义日志函数测试

    #!/user/bin/python # -*- encoding: UTF-8 -*- import sys def logs(): print sys._getframe().f_code.co_ ...

  9. centos问题集锦

    一. 为什么新装的centos系统无法使用xshell,putty等工具连接? 原因:sshd服务没有启动. 解决: 1)使用命令rpm -qa | grep ssh查看是否已经安装了ssh 2)使用 ...

  10. iOS 点击return或者点击屏幕键盘消失

    //定义两个文本框 UITextField *textName; UITextField *textSummary; //点击return 按钮 去掉 -(BOOL)textFieldShouldRe ...