zoukankan      html  css  js  c++  java
  • 【Ural1277】 Cops and Thieves 无向图点连通度问题

    1277. Cops and Thieves

    Time limit: 1.0 second
    Memory limit: 64 MB
    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 (x1, …, xN) separated with white-space character — the number of policemen required to control each of the stations (∑i=1Nxi ≤ 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.

    Samples

    inputoutput
    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
    

    题意大概是:封锁每一个点需要一个最少人数Ri,选择封锁几个点使得S,T的所有道路都被封锁.判断封锁需要的人数是否满足<=k

    题解:

    每一个点拆成两个点并建边(i,i+n,Ri),保证每个点只被经过一次。

    然后就是把每一条边(i,j)拆成(i+n,j,INF)和(j+n,i,INF);

    然后最小割就是最少人数 与k对比即可。

    注意特判S,T在同一点时的情况。

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm>
     5 #include<cmath>
     6 using namespace std;
     7 const int N=305,INF=1999999999;
     8 int gi(){
     9     int str=0;char ch=getchar();
    10     while(ch>'9'||ch<'0')ch=getchar();
    11     while(ch>='0' && ch<='9')str=str*10+ch-'0',ch=getchar();
    12     return str;
    13 }
    14 int head[N],q[N],dep[N],num=1,S,T;
    15 struct Lin{
    16     int next,to,dis;
    17 }a[N*N];
    18 void init(int x,int y,int z){
    19     a[++num].next=head[x];
    20     a[num].to=y;
    21     a[num].dis=z;
    22     head[x]=num;
    23     a[++num].next=head[y];
    24     a[num].to=x;
    25     a[num].dis=0;
    26     head[y]=num;
    27 }
    28 bool bfs()
    29 {
    30     memset(dep,0,sizeof(dep));
    31     int x,u,t=0,sum=1;dep[S]=1;q[1]=S;
    32     while(t!=sum)
    33     {
    34         x=q[++t];
    35         for(int i=head[x];i;i=a[i].next){
    36             u=a[i].to;
    37             if(a[i].dis<=0 || dep[u])continue;
    38             dep[u]=dep[x]+1;q[++sum]=u;
    39         }
    40     }
    41     return dep[T];
    42 }
    43 int dfs(int x,int flow)
    44 {
    45     if(x==T || !flow)return flow;
    46     int u,sum=0,tmp;
    47     for(int i=head[x];i;i=a[i].next){
    48         u=a[i].to;
    49         if(dep[u]!=dep[x]+1 || a[i].dis<=0)continue;
    50         tmp=dfs(u,min(flow,a[i].dis));
    51         a[i].dis-=tmp;a[i^1].dis+=tmp;
    52         sum+=tmp;flow-=tmp;
    53         if(!flow)break;
    54     }
    55     return sum;
    56 }
    57 int maxflow(){
    58     int tmp,tot=0;
    59     while(bfs()){
    60         tmp=dfs(S,INF);
    61         while(tmp)tot+=tmp,tmp=dfs(S,INF);
    62     }
    63     return tot;
    64 }
    65 int main()
    66 {
    67     int k=gi(),x,y;
    68     int n=gi(),m=gi();S=gi();T=gi();
    69     if(S==T){
    70         printf("NO
    ");
    71         return 0;
    72     }
    73     S+=n;
    74     for(int i=1;i<=n;i++){
    75         x=gi();
    76         init(i,i+n,x);
    77     }
    78     for(int i=1;i<=m;i++){
    79         x=gi();y=gi();
    80         init(x+n,y,INF);init(y+n,x,INF);
    81     }
    82     int pd=maxflow();
    83     if(pd<=k)printf("YES");
    84     else printf("NO");
    85     return 0;                    
    86 }
  • 相关阅读:
    参考SQLHelper编写的OracleHelper
    微软原版SQLHelper类
    AppFabric 版本区分
    ASP.NET (HttpModule,HttpHandler)
    ASP.NET内部原理(HttpHandler和HttpModule)
    IIS 7.0, ASP.NET, pipelines, modules, handlers, and preconditions
    理解I/O Completion Port
    asp.net mvc跨域filter
    c#生成MD5字符串
    生成格式化的json
  • 原文地址:https://www.cnblogs.com/Yuzao/p/6861273.html
Copyright © 2011-2022 走看看