题目链接:https://cn.vjudge.net/problem/URAL-1277

The Galaxy Police (Galaxpol) found out that a notorious gang of thieves has plans for stealing an extremely valuable exhibit from the Earth Planetary Museum — an ancient microprocessor. The police chiefs decided to intercept the criminals on the way from their refuge to the museum. A problem arose while planning the police operation: would it be possible for the Galaxpol staff to control all the possible routes of the criminals?
The galaxy transport system is designed as follows. Each planet has a transport station that is connected to some of the other stations via two-way teleportation channels. Transport stations vary in their sizes, so different numbers of policemen may be required to take control over different stations. In order not to upset the operation, it was decided to leave the planets that are next to the museum or the refuge without any police control.
Help the Galaxpol to place their staff at the stations in order to block all possible routes of the thieves.

Input

The first line of the input contains a single integer 0 < K ≤ 10000 — the number of policemen engaged to control the stations.
The second line has four integers: NMS and F delimited with white-space character.
N is the number of stations in the galaxy (the stations are numbered from 1 toN); 2 < N ≤ 100.
M is the number of teleportation channels; 1 < M ≤ 10000.
S is the number of the planet (and the station) where the museum is; 1 ≤ S ≤N.
F is the number of the planet (and the station) where the thieves’ refuge is; 1 ≤ F ≤ N.
The next line contains N integers ( x 1, …, xN) separated with white-space character — the number of policemen required to control each of the stations (∑ i=1 N xi ≤ 10000).
Then M lines follow that describe the teleportation channels. Each of these lines contains a pair of space-delimited integers — the numbers of stations being connected by a channel. The channel system is designed so that it is possible to reach any station from any other one (probably it would require several channel transitions).

Output

Write “YES” if it is possible to block all the possible routes within given limitations, and “NO” otherwise.

Example

input output
10
5 5 1 5
1 6 6 11 1
1 2
1 3
2 4
3 4
4 5
NO
10
5 5 1 5
1 4 4 11 1
1 2
1 3
2 4
3 4
4 5
YES

至于为什么要这样拆边,假设in(k)==k',out(k)==k'',即我们要addedge(out(i), in(j), INF)和addedge(out(j), in(i), INF),

为什么要这样addedge呢?因为我们的最大流算法默认都是有向图,addedge加入的边都是有向边,

这样加入边确保了该点k所有的入弧都是连接到in(k),出弧都是连接在out(k);

这使得原本所有流经该点的flow,现在都必须流经edge(in(k), out(k), w),确保了算法的正确性(不是很清楚的话,可以手动画图拆点拆边试试)。

(原本我想当然的addedge(out(i), in(j), INF)和addedge(in(j), in(i), INF),果断WA了……)

 #include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#define MAX 2*100+5
#define INF 0x3f3f3f3f
#define in(x) x
#define out(x) x+N
using namespace std;
int K,N,M,S,F;
struct Edge{
int u,v,c,f;
};
struct Dinic
{
int s,t;
vector<Edge> E;
vector<int> G[MAX];
bool vis[MAX];
int lev[MAX];
int cur[MAX];
void addedge(int from,int to,int cap)
{
E.push_back((Edge){from,to,cap,});
E.push_back((Edge){to,from,,});
G[from].push_back(E.size()-);
G[to].push_back(E.size()-);
}
bool bfs()
{
memset(vis,,sizeof(vis));
queue<int> q;
q.push(s);
lev[s]=;
vis[s]=;
while(!q.empty())
{
int now=q.front(); q.pop();
for(int i=,_size=G[now].size();i<_size;i++)
{
Edge edge=E[G[now][i]];
int nex=edge.v;
if(!vis[nex] && edge.c>edge.f)
{
lev[nex]=lev[now]+;
q.push(nex);
vis[nex]=;
}
}
}
return vis[t];
}
int dfs(int now,int aug)
{
if(now==t || aug==) return aug;
int flow=,f;
for(int& i=cur[now],_size=G[now].size();i<_size;i++)
{
Edge& edge=E[G[now][i]];
int nex=edge.v;
if(lev[now]+ == lev[nex] && (f=dfs(nex,min(aug,edge.c-edge.f)))>)
{
edge.f+=f;
E[G[now][i]^].f-=f;
flow+=f;
aug-=f;
if(!aug) break;
}
}
return flow;
}
int maxflow()
{
int flow=;
while(bfs())
{
memset(cur,,sizeof(cur));
flow+=dfs(s,INF);
}
return flow;
}
}dinic;
int main()
{
scanf("%d%d%d%d%d",&K,&N,&M,&S,&F);
for(int i=,x;i<=N;i++)
{
scanf("%d",&x);
dinic.addedge(in(i),out(i),x);
dinic.addedge(out(i),in(i),x);
}
for(int i=,a,b;i<=M;i++)
{
scanf("%d%d",&a,&b);
dinic.addedge(out(a),in(b),INF);
dinic.addedge(out(b),in(a),INF);
}
if(S==F){
printf("NO\n");
return ;
}
dinic.s=out(S), dinic.t=in(F);
if(dinic.maxflow()<=K) printf("YES\n");
else printf("NO\n");
return ;
}

最新文章

  1. css中vw,vh单位对于UC的兼容性问题
  2. dedecms 后台发布后的文章不能编辑出现一片空白的解决办法
  3. [solr] - Facet
  4. [ITSEC]信息安全&#183;Web安全培训第一期客户端安全之UBB系列
  5. Server Application Unavailable出现的原因及解决方案集锦
  6. JAVA SERVLET专题(上)
  7. 常用应用层协议HTTP、RTSP、RTMP比较
  8. 10+ 最流行的 jQuery Tree 菜单插件
  9. FCKeditor插件开发实例:uploadify多文件上传插件
  10. 一道关于CSS选择器优先级的题
  11. 获取VB类模块成员函数指针(转)
  12. Codeforces Round #384 (Div. 2).C
  13. Intellj IDEA光标为insert状态,无法删除内容
  14. 谈一谈synchronized关键词
  15. 听翁恺老师mooc笔记(1)--为何选择学习C
  16. VS 2008 开发WinCE程序 编译部署速度慢的解决办法
  17. js倒计时一分钟
  18. FB面经Prepare: Dot Product
  19. django channle的使用
  20. javap浅析-书籍第3章的手写稿样稿

热门文章

  1. IOS UILineBreakMode的各种情况分析
  2. 利用OpenSSL库对Socket传输进行安全加密(RSA+AES)
  3. python中交换两个值的方法
  4. 【代码审计】iZhanCMS_v2.1 代码执行漏洞分析
  5. windows命令行下用netsh实现端口转发(端口映射)
  6. Redis 集群配置
  7. java如何调用另一个包里面的类
  8. Twitter的SnowFlake分布式id生成算法
  9. 【问题记录系列】the resource is not on the build path of a java project
  10. C# EF中调用 存储过程并调回参数