[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 ;
}

AC日记——[USACO5.4]奶牛的电信Telecowmunication 洛谷 P1345的更多相关文章

  1. P1345 [USACO5.4]奶牛的电信Telecowmunication

    P1345 [USACO5.4]奶牛的电信Telecowmunication 题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流.这些机器用如下的方式发送电邮 ...

  2. 题解 P1345 【[USACO5.4]奶牛的电信Telecowmunication】

    P1345 [USACO5.4]奶牛的电信Telecowmunication 题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流.这些机器用如下的方式发送电邮 ...

  3. 洛谷P1345 [USACO5.4]奶牛的电信Telecowmunication【最小割】分析+题解代码

    洛谷P1345 [USACO5.4]奶牛的电信Telecowmunication[最小割]分析+题解代码 题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流. ...

  4. 洛谷——P1345 [USACO5.4]奶牛的电信Telecowmunication

    P1345 [USACO5.4]奶牛的电信Telecowmunication 题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流.这些机器用如下的方式发送电邮 ...

  5. [USACO5.4]奶牛的电信Telecowmunication(网络流)

    P1345 [USACO5.4]奶牛的电信Telecowmunication 题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流.这些机器用如下的方式发送电邮 ...

  6. [Luogu P1345] [USACO5.4]奶牛的电信Telecowmunication (最小割)

    题面 传送门:https://www.luogu.org/problemnew/show/P1345 ] Solution 这道题,需要一个小技巧了解决. 我相信很多像我这样接蒟蒻,看到这道题,不禁兴 ...

  7. 洛谷P1345 [USACO5.4]奶牛的电信Telecowmunication

    题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流.这些机器用如下的方式发送电邮:如果存在一个由c台电脑组成的序列a1,a2,...,a(c),且a1与a2相 ...

  8. 洛谷P13445 [USACO5.4]奶牛的电信Telecowmunication(网络流)

    题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流.这些机器用如下的方式发送电邮:如果存在一个由c台电脑组成的序列a1,a2,...,a(c),且a1与a2相 ...

  9. 洛谷P1345 [USACO5.4]奶牛的电信Telecowmunication(最小割)

    题目描述 农夫约翰的奶牛们喜欢通过电邮保持联系,于是她们建立了一个奶牛电脑网络,以便互相交流.这些机器用如下的方式发送电邮:如果存在一个由c台电脑组成的序列a1,a2,...,a(c),且a1与a2相 ...

随机推荐

  1. Java中将对象转换为Map的方法

    将对象转换为Map的方法,代码如下: /** * 将对象转成TreeMap,属性名为key,属性值为value * @param object 对象 * @return * @throws Illeg ...

  2. Overlaying GPS Coordinates for Camera Crosshairs

    Hey Guys! I am working on a project to allow us to implement GPS coordinates for the location of the ...

  3. Codeforces Round #340 (Div. 2) E 莫队+前缀异或和

    E. XOR and Favorite Number time limit per test 4 seconds memory limit per test 256 megabytes input s ...

  4. Android MediaRecorder解析

    源码路径:frameworks/base/media/java/android/media/MediaRecorder.javaframeworks/base/media/jni/android_me ...

  5. 题解 P3153 【[CQOI2009]跳舞】

    P3153 [CQOI2009]跳舞 题目描述 一次舞会有n个男孩和n个女孩.每首曲子开始时,所有男孩和女孩恰好配成n对跳交谊舞.每个男孩都不会和同一个女孩跳两首(或更多)舞曲.有一些男孩女孩相互喜欢 ...

  6. [DeeplearningAI笔记]卷积神经网络1.9-1.11池化层/卷积神经网络示例/优点

    4.1卷积神经网络 觉得有用的话,欢迎一起讨论相互学习~Follow Me 1.9池化层 优点 池化层可以缩减模型的大小,提高计算速度,同时提高所提取特征的鲁棒性. 池化层操作 池化操作与卷积操作类似 ...

  7. 在Centos系统下使用命令安装gnome图形界面程序

    第一步:先检查yum 是否安装了,以及网络是否有网络.如果这两者都没有,先解决网络,在解决yum的安装. 第二步:在命令行下 输入下面的命令来安装Gnome包. # yum groupinstall ...

  8. Jugs(回溯法)

    ZOJ Problem Set - 1005 Jugs Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge In ...

  9. MagicB.0—怎样设置电脑自动关机?

    天太晚了,该睡觉了,可是你的东西也许正在下载,软件正在更新,总之电脑还有一些工作没有完成,又不需要你人为的守着,随他去吧!可是电脑已经工作了一天了,它也要休息一下,再者也不能浪费电力资源呀,那么就来使 ...

  10. 【BZOJ】3036: 绿豆蛙的归宿

    [题意]给定DAG带边权连通图,保证所有点都能到达终点n,每个点等概率沿边走,求起点1到终点n的期望长度.n<=10^5. [算法]期望DP [题解]f[i]表示到终点n的期望长度. f[n]= ...