传送门

洛谷

Solution

emmm,直接对于每一个点拆点就好了。

然后边连Inf,点连1,跑最小割就是答案。

代码实现

#include<bits/stdc++.h>
using namespace std;
const int N=100010,Inf=1e9+10;
int front[N],cnt,s,t,n;
struct node
{
int to,nxt,w;
}e[500010];
queue<int>Q;
int dep[N];
void Add(int u,int v,int w)
{
e[cnt]=(node){v,front[u],w};front[u]=cnt++;
e[cnt]=(node){u,front[v],0};front[v]=cnt++;
}
bool bfs()
{
memset(dep,0,sizeof(dep));
Q.push(s);dep[s]=1;
while(!Q.empty())
{
int u=Q.front();Q.pop();
for(int i=front[u];i!=-1;i=e[i].nxt)
{
int v=e[i].to;
if(!dep[v] && e[i].w)
{
dep[v]=dep[u]+1;Q.push(v);
}
}
}
return dep[t];
}
int dfs(int u,int flow)
{
if(u==t || !flow)return flow;
for(int i=front[u];i!=-1;i=e[i].nxt)
{
int v=e[i].to;
if(dep[v]==dep[u]+1 && e[i].w)
{
int di=dfs(v,min(flow,e[i].w));
if(di)
{
e[i].w-=di;e[i^1].w+=di;
return di;
}
else dep[v]=0;
}
}
return 0;
}
int dinic()
{
int flow=0;
while(bfs())
{
while(int d=dfs(s,Inf))flow+=d;
}
return flow;
}
int m;
int main()
{
memset(front,-1,sizeof(front));
scanf("%d%d%d%d", &n,&m,&s,&t);
t+=n;
for(int i=1;i<=n;i++)
if(i!=s && (i!=t-n))Add(i,i+n,1);
else Add(i,i+n,Inf);
while(m--)
{
int u,v;scanf("%d%d",&u,&v);
Add(u+n,v,Inf);
Add(v+n,u,Inf);
}
printf("%d\n",dinic());
return 0;
}

最新文章

  1. 諾基亞定制的Android系統名為 Z Launcher
  2. C++ 非阻塞套接字的使用 (3)
  3. JSP的原理
  4. Codeforces 86D Powerful array(莫队算法)
  5. Date Picker Calendar For Oracle Forms 6i
  6. js net 除法取整
  7. python 自动化之路 day 04.1 python内置函数
  8. OA请假流程 -- 编码
  9. radio 和checkbox与文字对齐问题
  10. 奇妙的go语言(聊天室的开发)
  11. attribute和property兼容性分析
  12. ABP官方文档翻译 6.2.1 ASP.NET Core集成
  13. 文件系统扫描工具-fsck
  14. ping百度域名时的收获
  15. go 方法
  16. 开发中经常遇到SVN清理失败的问题:
  17. CentOS7 下curl使用
  18. Vue2.5开发去哪儿网App 第五章笔记 上
  19. golang init函数
  20. Spring的配置文件ApplicationContext.xml配置头文件解析

热门文章

  1. Visual Studio新建类自动添加注释
  2. 感兴趣的WebGL ,来自微博的一个全景星空图~
  3. VBA精彩代码分享-1
  4. LeetCode 腾讯精选50题--求众数
  5. jumpserver跳板机docker安装小小趟坑
  6. Hadoop_17_MapRduce_案例2_实现用户手机流量统计(ReduceTask并行度控制)
  7. linux下搭建redis内网端口映射工具-rinetd
  8. Gym - 102141D 通项公式 最短路
  9. python 判断数据类型及释疑
  10. Java入门第二季——第4章 多态