栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 2788 Panic Room

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 2788 Panic Room

#include <cstdlib>#include <cstring>#include <cstdio>#include <algorithm>#include <iostream>using namespace std;int N, M, TT;const int SS = 40;const int INF = 0x3fffffff;struct Edge {    int v, c, next;    };Edge e[10000];int idx, head[50];int lv[50], que[50];int front, tail;void insert(int a, int b, int c) {    e[idx].v = b, e[idx].c = c;    e[idx].next = head[a];    head[a] = idx++;}bool bfs() {    front = tail = 0;    memset(lv, 0xff, sizeof (lv));    lv[SS] = 1;    que[tail++] = SS;    while (front < tail) {        int u = que[front++];        for (int i = head[u]; i != -1; i = e[i].next) { int v = e[i].v; if (!(~lv[v]) && e[i].c) {     lv[v] = lv[u] + 1;     if (v == TT) return true;     que[tail++] = v;     }        }    }    return false;}int dfs(int u, int sup) {    if (u == TT) return sup;    int tf = 0, f;    for (int i = head[u]; i != -1; i = e[i].next) {        int v = e[i].v;        if (lv[u]+1==lv[v] && e[i].c && (f=dfs(v, min(e[i].c, sup-tf)))) { tf += f; e[i].c -= f, e[i^1].c += f; if (tf == sup) return sup; }    }    if (!tf) lv[u] = -1;    return tf;}int dinic() {    int ret = 0;    while (bfs()) {        ret += dfs(SS, INF);        }    return ret;}int main() {    int T;    scanf("%d", &T);    while (T--) {        int x, y;        char op[5];        idx = 0;        memset(head, 0xff, sizeof (head));        scanf("%d %d", &M, &N);        TT = N;        for (int i = 0; i < M; ++i) { scanf("%s %d", op, &x); if (op[0] == 'I') {     insert(SS, i, INF);     insert(i, SS, 0); } for (int j = 0; j < x; ++j) {     scanf("%d", &y);     insert(i, y, INF);     insert(y, i, 1); }        }        int ans = dinic();        if (ans < INF) { printf("%dn", ans);        } else { puts("PANIC ROOM BREACH");        }    }    return 0;    }
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/372617.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号