HDU4289 水题...

 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
Input
  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 10 7.
  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).
Output
  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
5
2
3
4
12
1 5
5 4
2 3
2 4
4 3
2 1
Sample Output
3

既然问的是弄死哪个点的最小割…
那明显不就是拆点嘛….
路全是inf
自己连自己是代价…

#include<iostream>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;
const int inf = 0x3fffffff;
template <int N, int M>
struct Isap
{
    int top;
    int d[N], pre[N], cur[N], gap[N];
    struct Vertex {
        int head;
    } V[N];
    struct Edge {
        int v, next;
        int c, f;
    } E[M];
    void init() {
        memset(V, -1, sizeof(V));
        top = 0;
    }
    void add_edge(int u, int v, int c) {
        E[top].v = v;
        E[top].c = c;
        E[top].f = 0;
        E[top].next = V[u].head;
        V[u].head = top++;
    }
    void add(int u, int v, int c) {
        add_edge(u, v, c);
        add_edge(v, u, 0);
    }
    void set_d(int t) {
        queue<int> Q;
        memset(d, -1, sizeof(d));
        memset(gap, 0, sizeof(gap));
        d[t] = 0;
        Q.push(t);
        while (!Q.empty()) {
            int v = Q.front(); Q.pop();
            ++gap[d[v]];
            for (int i = V[v].head; ~i; i = E[i].next) {
                int u = E[i].v;
                if (d[u] == -1) {
                    d[u] = d[v] + 1;
                    Q.push(u);
                }
            }
        }
    }
    int sap(int s, int t, int num) {
        set_d(t);
        int ans = 0, u = s;
        int flow = inf;
        memcpy(cur, V, sizeof(V));
        while (d[s] < num) {
            int &i = cur[u];
            for (; ~i; i = E[i].next) {
                int v = E[i].v;
                if (E[i].c > E[i].f && d[u] == d[v] + 1) {
                    u = v;
                    pre[v] = i;
                    flow = min(flow, E[i].c - E[i].f);
                    if (u == t) {
                        while (u != s) {
                            int j = pre[u];
                            E[j].f += flow;
                            E[j ^ 1].f -= flow;
                            u = E[j ^ 1].v;
                        }
                        ans += flow;
                        flow = inf;
                    }
                    break;
                }
            }
            if (i == -1) {
                if (--gap[d[u]] == 0)
                    break;
                int dmin = num - 1;
                cur[u] = V[u].head;
                for (int j = V[u].head; ~j; j = E[j].next)
                    if (E[j].c > E[j].f)
                        dmin = min(dmin, d[E[j].v]);
                d[u] = dmin + 1;
                ++gap[d[u]];
                if (u != s)
                    u = E[pre[u] ^ 1].v;
            }
        }
        return ans;
    }
};
Isap<100005, 200005> Sap;
int main()
{
    int n, m;
    while (cin >> n >> m)
    {
        Sap.init();
        int q, w;
        cin >> q >> w;
        int qq = q, ww = w;
        int st = 3 * n, zt = 3 * n + 1;
        Sap.add(st, q, inf);
        Sap.add(w+n, zt, inf);
        for (int a = 1; a <= n; a++)
        {
            cin >> q;
    //      if (a == qq || a == ww)continue;
            Sap.add(a, a + n, q);
        }
        for (int a = 1; a <= m; a++)
        {
            cin >> q >> w;
//          if (q != qq&&w != ww)
//          {
                Sap.add(q + n, w, inf);
                Sap.add(w + n, q, inf);
//          }
        }
        cout << Sap.sap(st, zt, 15 * m + 6 * n) << endl;
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值