Extra Judicial Operation
Description
The Suitably Protected Programming Contest (SPPC) is a multi-site contest in which contestants compete at specified sites, which are linked by the Notorious Broken Network (NBN) of two-way links between some pairs of individual sites. There is at most one link directly between any pair of sites and there is no link from a site to itself. Contestants submit their solutions to a judging server to get them tested. The event will use one or more judging servers. Each judging server is located at a contest site and may be accessed directly from that site or through a sequence of linked sites. At any time during the contest, each contestant must have access to at least one judging server. The links between sites are set up in such a way that if all links work properly, it would suffice to operate one judging server. At the other extreme, having each site operate its own judging server would guarantee access even if all of the links failed. The organisers wish to minimise the number of judging servers that they operate, while still maintaining the integrity of the contest. Examination of the NBN’s performance over time reveals some good news. The NBN is reliably unreliable! At any given time, exactly one link is broken (that is, communications cannot travel in either direction on that link). Given this fact, the organisers want you to work out the minimum number of judging servers that must operate so that no matter which link is broken, every contestant still has access to at least one judging server. As they know that they must operate at least one judging server, they ask you to tell them how many extra judging servers they must operate.
Input
The first line of the input contains a single integer S (2 ≤ S ≤ 100 000), which is the number of sites. The sites are numbered from 0 to S − 1. The next S lines describe the sites. Each of these lines starts with an integer l (0 ≤ l < S), which is the number of links that this site has to a site with a larger number. Then follow ‘ integers in ascending order, which are the sites to which those links go. Note that, although links are two-way, they are only mentioned in the lower numbered site’s line. The total number of links is no more than 100 000.
Output
Display the minimum number of extra judging servers the organisers must operate.
Sample Input
4
3 1 2 3
0
0
0
Sample Output
2 给你一个无向图 ,任意删除一条边,
要使得每一个点都能在这个它所在的图里面能到达每一个点,任意两点都有路径 问最少需要几个点才能满足条件
其实就是问这个无向图缩点后度为于1的点有多少个
注意 一开始说了有1个点了,所以要减去1
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
using namespace std; const int maxn = 3e5 + ;
int n, m, u, v, tot, top, cnt, flag;
struct node {
int u, v, next;
} edge[maxn];
int head[maxn], instack[maxn], s[maxn];
int dfn[maxn], low[maxn], belong[maxn];
void init() {
tot = cnt = top = flag = ;
memset(s, , sizeof(s));
memset(head, -, sizeof(head));
memset(dfn, , sizeof(dfn));
memset(instack, , sizeof(instack));
}
void add(int u, int v) {
edge[tot].v = v;
edge[tot].u = u;
edge[tot].next = head[u];
head[u] = tot++;
}
void tarjin(int v, int fa) {
dfn[v] = low[v] = ++flag;
instack[v] = ;
s[top++] = v;
for (int i = head[v] ; i != - ; i = edge[i].next) {
int j = edge[i].v;
if (j == fa) continue;
if (!instack[j]) {
tarjin(j, v);
low[v] = min(low[v], low[j]);
} else if (instack[j] == ) low[v] = min(low[v], dfn[j]);
}
if (dfn[v] == low[v]) {
cnt++;
int t;
do {
t = s[--top];
instack[t] = ;
belong[t] = cnt;
} while(t != v) ;
}
}
int du[maxn];
int main() {
while(scanf("%d", &n) != EOF) {
init();
memset(du, , sizeof(du));
for (int i = ; i <= n ; i++) {
int x, y;
scanf("%d", &x);
while(x--) {
scanf("%d", &y);
y++;
add(i, y);
add(y, i);
}
}
for (int i = ; i <= n ; i++)
if (!instack[i]) tarjin(i, -);
for(int i = ; i <= tot; i += ) {
if(belong[edge[i].u] != belong[edge[i].v]) {
du[belong[edge[i].u]]++;
du[belong[edge[i].v]]++;
}
}
int ans = ;
for (int i = ; i <= cnt ; i++)
if (du[i]==) ans++;
printf("%d\n", max(ans-, ));
}
return ;
}
Extra Judicial Operation的更多相关文章
- mysql in 子查询 效率慢 优化(转)
mysql in 子查询 效率慢 优化(转) 现在的CMS系统.博客系统.BBS等都喜欢使用标签tag作交叉链接,因此我也尝鲜用了下.但用了后发现我想查询某个tag的文章列表时速度很慢,达到5秒之久! ...
- iOS消息体系架构详解-融云即时通讯云
iOS SDK 体系架构 本文档将详细介绍融云的 SDK 产品架构和消息体系,以便于您更深入的了解融云并更快速的开发自己的产品. 融云 SDK 系统架构 IMKit IMKit 的功能主要是封装各种界 ...
- Web Reference for a WCF Service has Extra “IdSpecified” Parameter ?
Question: I created a WCF service that exposed a method that has one paramater: public class Service ...
- Exception: Operation xx of contract xx specifies multiple request body parameters to be serialized without any wrapper elements.
Operation 'CreateProductCodeStock' of contract 'IChileService' specifies multiple request body param ...
- RFC 8684---TCP Extensions for Multipath Operation with Multiple Addresses
https://datatracker.ietf.org/doc/rfc8684/?include_text=1 TCP Extensions for Multipath Operation with ...
- 终端mysql Operation not permitted错误解决方案
前言 前段时间装mysql,就遇到了ln: /usr/bin/mysql: Operation not permitted的错误,网上好多方法都过时了,下边是我的解决方法 原因 这是因为苹果在OS X ...
- SVN:Previous operation has not finished; run 'cleanup' if it was interrupted
异常处理汇总-开发工具 http://www.cnblogs.com/dunitian/p/4522988.html cleanup failed to process the following ...
- Mysql Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation '='
MySQL字符串比较bug: select * from table_a a left join table_b b on a.field_a = b.field_b error: Illegal ...
- TNS-12535: TNS:operation timed out案例解析
一数据库突然连接不上,在自己电脑上使用SQL Developer也连接不上.立即使用SecureCRT连接上了这台服务器,从下面几个方面检查. 1:检查了数据库的状态是否正常 $ sqlplus / ...
随机推荐
- Git的基本命令介绍
Git的安装 进入官网下载系统所需要的版本 官网地址:https://git-scm.com/downloads 点击下载按钮官方网站一般会根据操作系统的自动下载所需要的Git版本. 下载完成后,点 ...
- JZOJ 5919. 逛公园
Description 琥珀色黄昏像糖在很美的远方,思念跟影子在傍晚一起被拉长……Description 小 B 带着 GF 去逛公园,公园一共有 n 个景点,标号为 ...
- JavaScript通过HTML的class来获取HTML元素的方法总结
对于js来说,我想每一个刚接触它的人都应该会抱怨:为什么没有一个通过class来获取元素的方法.尽管现在高版本的浏览器已经支持getElementsByClassName()函数,但是对于低版本浏览器 ...
- 部分和问题 南阳acm1058(递归+dfs)
部分和问题 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 给定整数a1.a2........an,判断是否可以从中选出若干数,使它们的和恰好为K. 输入 首先, ...
- 操作视频-对视频进行canny边缘检测
#include<opencv2/opencv.hpp> using namespace cv; int main() { VideoCapture capture(); //从摄像头读入 ...
- Mysql处理海量数据时的一些优化查询速度方法【转】
最近一段时间由于工作需要,开始关注针对Mysql数据库的select查询语句的相关优化方法.由于在参与的实际项目中发现当mysql表的数据量达到百万级时,普通SQL查询效率呈直线下降,而且如果wher ...
- hdu1251统计难题(trie)
统计难题 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131070/65535 K (Java/Others)Total Submi ...
- svn git 导入本地文件到远程服务器 import
以前,想要把本地的一个文件上传到svn 或者git 服务器的时候,都要先把服务器上的文件夹down 下来,然后把要添加的文件添加进去,然后提交. 想想都麻烦. 现在我们用import 命令就可以做到, ...
- hadoop集群之Datenode无法启动解决办法
hadoop集群之Datenode无法启动解决办法 我们在启动hadoop集群的时候,通过jps查看进程,发现namenode RM和Secondary NameNode都有,但datanode没有启 ...
- Nodejs-异步操作
1.阻塞 console.time('main');//代码计时器 //不断循环阻塞了代码的执行 for(var i=0;i<10000000;i++){ } console.timeEnd(' ...