/*边联通度的题;给定n个门,每个门连接两个房间,门面向其中的一个房间x,
从这个房间x任意情况都可以到另外一个房间y,y只能在门开着的时候可以进入x,
其中有些房间有入侵者,现在求解至少关几个门,可以保护某个房间的安全
对于x,y之间面向x的门,连x到y的边,流量无穷,y到x的边,流量1
增加一个源点,标号为m,连接源点到有入侵者的点,流量无穷,要保护的点
作为汇点.如果最大流为无穷,则不存在保护方案,反之,最大流即是最少要关的门的数量*/
//SAP版本
#include<cstdio>
#include<cstring>
#include<queue>
#include<iostream>
const int N=11000,M=100100,INF=1e8,L=999999;
using namespace std;
struct Edge{int dest,len,next;}edge[M];
int p[M],pi;
void Insert(int a,int b,int len){edge[pi].dest=b;edge[pi].len=len;edge[pi].next=p[a];p[a]=pi++;edge[pi].dest=a;edge[pi].len=0;  edge[pi].next=p[b];p[b]=pi++;
}
int dis[N],pre[N],cur[N],gap[N];
int sap(int s,int t,int n){int i,ans=0,now=pre[s]=s,dest,mmin=INF;for(i=0;i<n;i++){cur[i]=p[i];dis[i]=gap[i]=0;}gap[s]=n;bool flag;while(dis[s]<n){flag=false;for(i=cur[now];i!=-1;i=edge[i].next){cur[now]=i;dest=edge[i].dest;if(dis[now]==dis[dest]+1&&edge[i].len>0){flag=true;mmin=min(mmin,edge[i].len);pre[dest]=now;now=dest;if(now==t){ans+=mmin;while(now!=s){now=pre[now];edge[cur[now]].len-=mmin;edge[cur[now]^1].len+=mmin;}mmin=INF;}break;}}if(flag)continue;int mindis=n;for(i=p[now];i!=-1;i=edge[i].next){dest=edge[i].dest;if(edge[i].len>0&&dis[now]<mindis){mindis=dis[now];cur[now]=i;}}if((--gap[dis[now]])==0)break;gap[dis[now]=mindis+1]++;//真是奇葩代码now=pre[now];}return ans;
}
int n,m;
void init(){int i,j,num,b;char op[3];memset(p,-1,sizeof(p));pi=0;scanf("%d%d",&m,&n);for(i=0;i<m;i++){scanf("%s",&op);if(op[0]=='I')Insert(m,i,L);scanf("%d",&num);for(j=0;j<num;j++){scanf("%d",&b);Insert(i,b,L);Insert(b,i,1);}}
}
int main(){int T;for(scanf("%d",&T);T--;){init();int ans=sap(m,n,m+1);if(ans>=L)printf("PANIC ROOM BREACH\n");else printf("%d\n",ans);}return 0;
}//标程
#include<cstdio>
#include<cstring>
#include<queue>
#include<iostream>
#define M 25
#define INF 5000
using namespace std;
int map[M][M],m,n,t,pre[M];
bool vis[M];
int Maxflow(){int ans=0;while(true){memset(vis,false,sizeof(vis));memset(pre,0,sizeof(pre));queue<int>q;q.push(m);//源点压入队列vis[m]=true;while(!q.empty()){int cur=q.front();q.pop();if(cur==n)break;for(int i=0;i<m;i++){if(!vis[i]&&map[cur][i]){vis[i]=true;q.push(i);pre[i]=cur;}}}if(!vis[n])break;int Min=INF,u;for(u=n;u!=m;u=pre[u]){if(Min>map[pre[u]][u])Min=map[pre[u]][u];}for(u=n;u!=m;u=pre[u]){map[pre[u]][u]-=Min;map[u][pre[u]]+=Min;}ans+=Min;}return ans;}
int main(){int i,u,v,room,mnt;string ch;for(scanf("%d",&t);t--;){memset(map,0,sizeof(map));scanf("%d%d",&m,&n);for(i=0;i<m;i++){cin>>ch>>mnt;if(ch=="I")map[m][i]=INF;while(mnt--){scanf("%d",&v);map[i][v]=INF;map[v][i]++;}}int ans=Maxflow();if(ans>=INF)printf("PANIC ROOM BREACH\n");else printf("%d\n",ans);}return 0;
}

Panic Room

Time Limit:1000MS    Memory Limit:65536KB


Description

You are the lead programmer for the Securitron 9042, the latest and greatest in home security software from Jellern Inc. (Motto: We secure your stuff so YOU can't even get to it). The software is designed to "secure" a room; it does this by determining the minimum number of locks it has to perform to prevent access to a given room from one or more other rooms. Each door connects two rooms and has a single control panel that will unlock it. This control panel is accessible from only one side of the door. So, for example, if the layout of a house looked like this:

with rooms numbered 0-6 and control panels marked with the letters "CP" (each next to the door it can unlock and in the room that it is accessible from), then one could say that the minimum number of locks to perform to secure room 2 from room 1 is two; one has to lock the door between room 2 and room 1 and the door between room 3 and room 1. Note that it is impossible to secure room 2 from room 3, since one would always be able to use the control panel in room 3 that unlocks the door between room 3 and room 2.

Input

Input to this problem will begin with a line containing a single integer x indicating the number of datasets. Each data set consists of two components:

  1. Start line – a single line "m n" (1 <=m<= 20; 0 <=n<= 19) where m indicates the number of rooms in the house and n indicates the room to secure (the panic room).

  2. Room list – a series of m lines. Each line lists, for a single room, whether there is an intruder in that room ("I" for intruder, "NI" for no intruder), a count of doors c (0 <= c <= 20) that lead to other rooms and have a control panel in this room, and a list of rooms that those doors lead to. For example, if room 3 had no intruder, and doors to rooms 1 and 2, and each of those doors' control panels were accessible from room 3 (as is the case in the above layout), the line for room 3 would read "NI 2 1 2". The first line in the list represents room 0. The second line represents room 1, and so on until the last line, which represents room m - 1. On each line, the rooms are always listed in ascending order. It is possible for rooms to be connected by multiple doors and for there to be more than one intruder!

Output

For each dataset, output the fewest number of locks to perform to secure the panic room from all the intruders. If it is impossible to secure the panic room from all the intruders, output "PANIC ROOM BREACH". Assume that all doors start out unlocked and there will not be an intruder in the panic room.

Sampleinput

3
7 2
NI 0
I 3 0 4 5
NI 2 1 6
NI 2 1 2
NI 0
NI 0
NI 0
7 2
I 0
NI 3 0 4 5
NI 2 1 6
I 2 1 2
NI 0
NI 0
NI 0
4 3
I 0
NI 1 2
NI 1 0
NI 4 1 1 2 2

Sampleoutput

2

PANIC ROOM BREACH

1

BOJ 15 Panic Room相关推荐

  1. linux源代码剖析之kernel

    kernel asm.s /* asm.s contains the low-level code for most hardware faults. page_exception is handle ...

  2. 2010款15寸Macbook Pro GPU panic崩溃问题解决方案

    本人拥有一台2010款15寸Macbook Pro笔记本电脑,自己动手升级了内存(8G),SSD硬盘(128G).赶着最新的潮流升级为最新版的MacOS 10.13,确实如广告宣称的:操作流畅.然而好 ...

  3. Go 语言 defer recover panic 简单例子

    为什么80%的码农都做不了架构师?>>>    // Mydef project main.go package mainimport ("log" )func ...

  4. Go 语言编程 — panic 和 recover

    目录 文章目录 目录 defer,panic 和 recover panic recover 通过 panic + recover 来简化错误处理 defer,panic 和 recover Gola ...

  5. golang log.Fatal() 和 panic() 函数的区别

    在讲两者区别之前我们先看一下os.Exit()函数的定义: func Exit(code int)Exit causes the current program to exit with the gi ...

  6. 关键字之defer、panic、recover

    一.defer                1. defer延迟调用,完成一些收尾工作.无论函数或方法是否出错,一定会在退出当前函数或者方法之前调用传入的函数(只对函数或方法生效,代码块不生效),常 ...

  7. sarama-cluster之panic: non-positive interval for NewTicker 问题

    go 常见问题记录 // 报错样式: panic: non-positive interval for NewTickergoroutine 59 [running]: time.NewTicker( ...

  8. 写一个 panic blame 机器人

    最近接手了一个"公共"服务,负责维护它的稳定性.代码库有很多人参与"维护",其实就是各种业务方使劲往上堆逻辑.虽然入库前我会进行 CR,但多了之后,也看不过来, ...

  9. 获取用户列表为空_数据结构和算法(Golang实现)(15)常见数据结构-列表

    列表 一.列表 List 我们又经常听到 列表 List 数据结构,其实这只是更宏观的统称,表示存放数据的队列. 列表 List:存放数据,数据按顺序排列,可以依次入队和出队,有序号关系,可以取出某序 ...

最新文章

  1. 项目管理利器taiga快速安装
  2. Java是如何加载资源文件的?(源码解毒)
  3. optee HSM的实现
  4. mysql怎么查看刷脏页慢_一条SQL查询语句极为缓慢,如何去优化呢
  5. Excel 【小型成绩分析系统初稿】(功能及适应性有待完善)
  6. UVA 11732 - strcmp() Anyone?(Trie)
  7. Linux tmux 使用指南
  8. 软考高项--项目管理概述
  9. 微信小程序:人生重开模拟器
  10. 最新2022中国大学排名发布!
  11. 王者荣耀战力查询微信小程序源码下载支持安卓苹果微信Q等多区查询
  12. 万字讲述如何通过Doris构建数据中台
  13. 【Java】GUI图形化界面中,setBounds()中参数的含义
  14. 计算机音乐数字谱铃舟,天涯明月刀手游音乐曲谱大全 天涯明月刀曲谱大全简单图片...
  15. Android R 通知新特性—人与对话(气泡窗)
  16. ios html格式转换,如何使用HTML模版和iOS中的UIPrintPageRenderer来生成PDF文档
  17. [HAL库学习之路]5.IWDG-独立看门狗
  18. AMOLED原理介紹
  19. 在进行多媒体计算机辅助教学,计算机多媒体辅助在数学教学中的应用
  20. VBA学习笔记5:将同一工作簿的数据按照类别拆分为多个工作簿

热门文章

  1. 总奖金近9万!视频超分辨率大赛等你来战!
  2. 实录分享 | 计算未来轻沙龙:深度学习工具专场(PPT下载)
  3. 使用PaddleFluid和TensorFlow训练RNN语言模型
  4. 算法竞赛入门与进阶 (四)二分
  5. Java反射机制的基本概念与使用_Java进阶之reflection(反射机制)——反射概念与基础...
  6. 解决IntelliJ IDEA 2019.3.5 启动无反应
  7. fastjson safemode_它又又又来了,Fastjson 最新高危漏洞来袭!
  8. 子类重写父类虚函数_C/C++编程笔记:关于C++的虚函数和多态,你真的了解吗?...
  9. wps电脑版_使用好这几个功能,让你手机里的wps变身神器。
  10. stream流【java8 二】