[USACO5.4]奶牛的电信Telecowmunication

思路:

  水题;

代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define maxn 205
#define maxm 20005
#define INF 0x3f3f3f3f
int head[maxn],cnt=,n,m,E[maxm],V[maxm],F[maxm],s,t;
int que[maxm<<],deep[maxn],c1,c2;
inline void in(int &now)
{
char Cget=getchar();now=;
while(Cget>''||Cget<'') Cget=getchar();
while(Cget>=''&&Cget<='')
{
now=now*+Cget-'';
Cget=getchar();
}
}
inline void edge_add(int u,int v,int f)
{
E[++cnt]=head[u],V[cnt]=v,F[cnt]=f,head[u]=cnt;
E[++cnt]=head[v],V[cnt]=u,F[cnt]=,head[v]=cnt;
}
bool bfs()
{
memset(deep,-,sizeof(deep));
int h=,tail=,now;que[]=s,deep[s]=;
while(h<tail)
{
now=que[h++];
for(int i=head[now];i;i=E[i])
{
if(deep[V[i]]<&&F[i])
{
deep[V[i]]=deep[now]+;
if(V[i]==t) return true;
que[tail++]=V[i];
}
}
}
return false;
}
int flowing(int now,int flow)
{
if(t==now||flow<=) return flow;
int oldflow=,pos;
for(int i=head[now];i;i=E[i])
{
if(!F[i]||deep[V[i]]!=deep[now]+) continue;
pos=flowing(V[i],min(flow,F[i]));
flow-=pos,oldflow+=pos,F[i]-=pos,F[i^]+=pos;
if(!flow) return oldflow;
}
if(!oldflow) deep[now]=-;
return oldflow;
}
int main()
{
in(n),in(m),in(c1),in(c2),s=c1+n,t=c2;
for(int i=;i<=n;i++) edge_add(i,i+n,);
while(m--)
{
in(c1),in(c2);
edge_add(c1+n,c2,INF);
edge_add(c2+n,c1,INF);
}
int ans=;
while(bfs()) ans+=flowing(s,INF);
cout<<ans;
return ;
}

最新文章

  1. UITableViewCell 的附件类型 accessoryType 选中、详情、箭头
  2. 小白挑战:AsyncTask源码分析
  3. 关于标准C语言的预定义宏【转】
  4. 查看Linux下网卡状态或 是否连接(转)
  5. WPF随手小记之二 ——改变DataGrid样式
  6. 使用纯css代码实现div的“回”字型“叠放”效果
  7. iOS常用控件尺寸大集合
  8. 一份完整的阿里云 Redis 开发规范,值得收藏!
  9. SpringMVC+Apache Shiro+JPA(hibernate)案例教学(三)给Shiro登录验证加上验证码
  10. [Swift]LeetCode775. 全局倒置与局部倒置 | Global and Local Inversions
  11. docker不能上传镜像到自己网站的仓库
  12. EF实现增删改查
  13. 创建MySQL用户 赋予某指定库表的权限
  14. 虚拟机安装及配置(centOs7)
  15. Android使用AIDL跨进程通信
  16. php数组去重(一维数组)
  17. 用jpinyin实现汉字转拼音功能
  18. MySQL权限和用户管理
  19. JS 面向对象详解
  20. [Compose] 19. Leapfrogging types with Traversable

热门文章

  1. HashCode与Equals回顾
  2. duilib CDateTimeUI 在Xp下的bug修复
  3. Python数据生成pdf文件
  4. Python之文件操作:os模块
  5. jeecms上传文件限制导致413-Request Entity Too Large
  6. KeyDown,KeyPress和KeyUp详解(转)
  7. SQL语句(二十二)—— 权限授予和回收(作业练习)
  8. Oracle笔记之序列(Sequence)
  9. 去掉input获取focus时的边框
  10. linux学习记录.1.安装