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
 1 #include <cstdio>
 2 #include <cstring>
 3 #include <string>
 4 #include <algorithm>
 5 #include <queue>
 6 using namespace std;
 7 
 8 const int maxn = 3e5 + 10;
 9 int n, m, u, v, tot, top, cnt, flag;
10 struct node {
11     int u, v, next;
12 } edge[maxn];
13 int head[maxn], instack[maxn], s[maxn];
14 int dfn[maxn], low[maxn], belong[maxn];
15 void init() {
16     tot = cnt = top = flag = 0;
17     memset(s, 0, sizeof(s));
18     memset(head, -1, sizeof(head));
19     memset(dfn, 0, sizeof(dfn));
20     memset(instack, 0, sizeof(instack));
21 }
22 void add(int u, int v) {
23     edge[tot].v = v;
24     edge[tot].u = u;
25     edge[tot].next = head[u];
26     head[u] = tot++;
27 }
28 void tarjin(int v, int fa) {
29     dfn[v] = low[v] = ++flag;
30     instack[v] = 1;
31     s[top++] = v;
32     for (int i = head[v] ; i != -1 ; i = edge[i].next) {
33         int j = edge[i].v;
34         if (j == fa) continue;
35         if (!instack[j]) {
36             tarjin(j, v);
37             low[v] = min(low[v], low[j]);
38         } else if (instack[j] == 1) low[v] = min(low[v], dfn[j]);
39     }
40     if (dfn[v] == low[v]) {
41         cnt++;
42         int t;
43         do {
44             t = s[--top];
45             instack[t] = 2;
46             belong[t] = cnt;
47         } while(t != v) ;
48     }
49 }
50 int du[maxn];
51 int main() {
52     while(scanf("%d", &n) != EOF) {
53         init();
54         memset(du, 0, sizeof(du));
55         for (int i = 1 ; i <= n ; i++) {
56             int x, y;
57             scanf("%d", &x);
58             while(x--) {
59                 scanf("%d", &y);
60                 y++;
61                 add(i, y);
62                 add(y, i);
63             }
64         }
65         for (int i = 1  ; i <= n ; i++)
66             if (!instack[i]) tarjin(i, -1);
67         for(int i = 0; i <= tot; i += 2) {
68             if(belong[edge[i].u] != belong[edge[i].v]) {
69                 du[belong[edge[i].u]]++;
70                 du[belong[edge[i].v]]++;
71             }
72         }
73         int ans = 0;
74         for (int i = 1 ; i <= cnt ; i++)
75             if (du[i]==1) ans++;
76         printf("%d
", max(ans-1, 0));
77     }
78     return 0;
79 }



原文地址:https://www.cnblogs.com/qldabiaoge/p/9078749.html