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 ;
}

最新文章

  1. Linux服务器配置之加载硬盘
  2. Android四大组件-Activity
  3. A very cool thing: Install MYSQL from source without root access on LINUX
  4. java文件上传下载
  5. 神奇的计算器dc和bc
  6. python 循环设计
  7. Android的一些常用命令提示符(cmd)指令
  8. XSS的原理分析与解剖(一)
  9. 去除重复命令uniq
  10. swift 自行理解
  11. arcengine 开发经典帖
  12. 使用Identity Server 4建立Authorization Server (3)
  13. Tomcat性能优化及JVM内存工作原理
  14. (五十九)iOS网络基础之UIWebView简易浏览器实现
  15. 真正的ddos防御之道,简单干脆有效!
  16. CentOS 7 install Tensorflow-gpu
  17. hadoop伪分布环境快速搭建
  18. Redis我想入门——数据类型
  19. 新建asp.net core项目
  20. org.apache.jasper.JasperException: /WEB-INF/view/../../../common/common1.jsp (line: 7, column: 1) Page directive must not have multiple occurrences of pageencoding

热门文章

  1. 执行pip命令时遇到 Fatal error in launcher: Unable to create process using &#39;&quot;&#39;
  2. 7-1 python 操作redis
  3. windows和linux上mysql的安装
  4. js如何获得系统时间年月日时分秒
  5. P1282
  6. 动态调试smali代码
  7. 代理缓存服务之Squid
  8. linux环境下kettle部署(JDK安装配置,kettle安装配置,资源库配置,定时执行job)
  9. Java 基本数据类型总结一
  10. 宝石TD迷宫设计器