URAL1277Cops and Thieves Dinic最大流

Description

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 to  N); 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.

Sample Input

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

首先弄明白题意要干嘛…… 在一个无向图中小偷要偷东西..小偷从s点出发..要偷的东在点e...警察可以用一些警力封锁一些点让小偷无论如何都不能到达e 求最小割
第一行的数字K,表示一共有这么多的警察,即最后的最大流不能超过这个数字。N星球个数,即点的个数。M:边的个数(最最原始,每两个点连着的边的个数)S: 起点    F:终点    下行每个点:每个星球所需警察数 再下面:连着的点对
如何建模是重点!据说最小割都是这么建模的,把一个点拆成两个 原来点上的权变成拆成两点间流的大小。最小割啊最小割~这么一说就明白了是不是~
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int inf=0x3f3f3f3f;
const int maxn=100000;
const int maxe=1000000;
int sum,s,e,head[maxn],level[maxn],que[maxn],n,m;
struct node{
     int w,to,next;
}edge[maxe];
inline void add(int u,int v,int c)
{
    edge[sum].to=v;
    edge[sum].w=c;
    edge[sum].next=head[u];
    head[u]=sum++;
    edge[sum].to=u;
    edge[sum].w=0;
    edge[sum].next=head[v];
    head[v]=sum++;
}
inline bool bfs()
{
    memset(level,0,sizeof(level));
    int p=0;
    que[p++]=s;
    level[s]=1;
    for(int i=0;i<p;i++)
    {
        int temp=que[i];
        for(int k=head[temp];k>-1;k=edge[k].next)
        if(edge[k].w && (!level[edge[k].to])){
            que[p++]=edge[k].to;
            level[edge[k].to]=level[temp]+1;
        }
    }
    return level[e];
}

int dfs(int now,int maxf)
{
    if(now==e)return maxf;
    int ret=0;
    for(int i=head[now];i>-1 && ret<maxf; i=edge[i].next)
    if(edge[i].w && (level[edge[i].to]==level[now]+1))
    {
        int temp=dfs(edge[i].to,min(maxf-ret,edge[i].w));
        edge[i].w-=temp;
        edge[i^1].w+=temp;
        ret+=temp;
    }
    if(ret==0)level[now]=0;
    return ret;
}

inline int dinic()
{
    int ans=0;
    while(bfs())ans+=dfs(s,inf);
    return ans;
}
int main()
{
    //freopen("cin.txt","r",stdin);
    int k,w,a,b;
    while(~scanf("%d",&k))
    {
        sum=0;
        memset(head,-1,sizeof(head));
        scanf("%d%d%d%d",&n,&m,&s,&e);
        s=s<<1|1;
        e=e<<1;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&w);
            add(i<<1,i<<1|1,w);
            add(i<<1|1,i<<1,w);
        }
        for(int i=0;i<m;i++)
        {
            scanf("%d%d",&a,&b);
            add(a<<1|1,b<<1,inf);
            add(b<<1|1,a<<1,inf);
        }
        if(dinic()<=k && s!=e+1 && s!=e-1 && s!=e) puts("YES");
        else puts("NO");
    }
    return 0;
}










  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值