Control Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4716    Accepted Submission(s): 1953 

Problem Description   

  You, the head of Department of Security, recently received a top-secret information that a group of terrorists is planning to transport some WMD 1 from one city (the source) to another one (the destination). You know their date, source and destination, and they are using the highway network.
  The highway network consists of bidirectional highways, connecting two distinct city. A vehicle can only enter/exit the highway network at cities only.
  You may locate some SA (special agents) in some selected cities, so that when the terrorists enter a city under observation (that is, SA is in this city), they would be caught immediately.
  It is possible to locate SA in all cities, but since controlling a city with SA may cost your department a certain amount of money, which might vary from city to city, and your budget might not be able to bear the full cost of controlling all cities, you must identify a set of cities, that:
  * all traffic of the terrorists must pass at least one city of the set.
  * sum of cost of controlling all cities in the set is minimal.
  You may assume that it is always possible to get from source of the terrorists to their destination.
1 Weapon of Mass Destruction


  There are several test cases.
  The first line of a single test case contains two integer N and M ( 2 <= N <= 200; 1 <= M <= 20000), the number of cities and the number of highways. Cities are numbered from 1 to N.
  The second line contains two integer S,D ( 1 <= S,D <= N), the number of the source and the number of the destination.
  The following N lines contains costs. Of these lines the ith one contains exactly one integer, the cost of locating SA in the ith city to put it under observation. You may assume that the cost is positive and not exceeding 107.
  The followingM lines tells you about highway network. Each of these lines contains two integers A and B, indicating a bidirectional highway between A and B.
  Please process until EOF (End Of File).


  For each test case you should output exactly one line, containing one integer, the sum of cost of your selected set.
  See samples for detailed information.

Sample Input

5 6

5 3






1 5

5 4

2 3

2 4

4 3

2 1

Sample Output



2012 ACM/ICPC Asia Regional Chengdu Online

有N个城市,S是歹徒的初始位置,D是歹徒将要去的位置,警方不知道他们的具体位置,所以选择封锁城市来消灭歹徒, 不过封锁城市是需要一定的代价的,所以让你求阻断歹徒从S到D需要的最小代价。 这是最小割,但是最大流=最小割,所以可以转换成最大流问题,需要注意的是双向边,所以我们需要转化成有向边来使用 最大流来解决,然后是拆点,把一个城市拆成两个。

 关于建图:这里将每个点拆成两个点(i ,i + n)然后i与i + n 的权值为该城市的代价,反向边为0; 两个城市之间:(u,v)则建立(u + n,v)  (v + n,u)权值为inf 这里他们的反向边都为0;


N,M 城市的数量 高速公路的数量
城市从 1->N 编号,
S,D 源的编号和目的地的编号
一下M行 是高速公路网络的信息,
#include <iostream>
#include <cstring>
#include <algorithm>
#include <string>
#include <cstdio>
#include <queue>
#include <stack>
using namespace std;
const int inf=0x3f3f3f3f;
const int maxn=110000;
struct Edge
    int to,w,next;
int tot,head[maxn],level[maxn];
void add_edge(int u,int v,int w)

int BFS(int s,int t)
    queue<int > que;
        int u=que.front();
        for(int i=head[u];i!=-1;i=edge[i].next)
            int v=edge[i].to;
                    return 1;
    }return 0;
int DFS(int u,int t,int f)
        return f;
    int cost=0;
    for(int i=head[u];i!=-1;i=edge[i].next)
        int v=edge[i].to;
        int w=edge[i].w;
            int d=DFS(v,t,min(w,f-cost));
                else level[v]=-1;
    }return cost;
int Dinic(int s,int t)
    int maxflow=0;
    return maxflow;
int main()
    int n,m;
        int s,t,u,v,w;
        for(int i=1;i<=n;i++)
            //拆点 把一个城市拆成两个,这两点的容量就为该点的消费量
        for(int i=1;i<=m;i++)
            scanf("%d%d",&u,&v);//连接的两个城市(一定能走通 所以赋值inf)
            add_edge(v+n,u,inf);//不同城市之间的流量为 inf
    }return 0;



年轻也需要有所作为( ・´ω`・ )