-
Notifications
You must be signed in to change notification settings - Fork 4
/
UVA00315.cpp
51 lines (48 loc) · 1.35 KB
/
UVA00315.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <vector>
#include <sstream>
using namespace std;
typedef vector<int> vi;
vector<vi> AdjList;
vi dfs_num, dfs_low;
vector<bool> apoints;
int counter, n0;
void artpoint(int n, int p) {
dfs_num[n] = dfs_low[n] = counter++;
for (int i = 0; i < AdjList[n].size(); i++) {
if (dfs_num[AdjList[n][i]] == -1) {
if (n == 0) n0++;
artpoint(AdjList[n][i], n);
if (dfs_low[AdjList[n][i]] >= dfs_num[n]) apoints[n] = true;
else dfs_low[n] = min(dfs_low[n], dfs_low[AdjList[n][i]]);
} else if (AdjList[n][i] != p) {
dfs_low[n] = min(dfs_low[n], dfs_num[AdjList[n][i]]);
}
}
}
int main() {
int N;
while (cin >> N && N != 0) {
string s;
AdjList.assign(N, vi());
while (getline(cin, s) && s != "0") {
istringstream iss(s);
int n1, n2;
iss >> n1;
while (iss >> n2) {
AdjList[n1-1].push_back(n2-1);
AdjList[n2-1].push_back(n1-1);
}
}
n0 = counter = 0;
apoints.assign(N, false);
dfs_num.assign(N, -1);
dfs_low.assign(N, -1);
artpoint(0, 0);
int ap = 0;
apoints[0] = (n0 > 1);
for (int i = 0; i < N; i++) if (apoints[i]) ap++;
printf("%d\n", ap);
}
return 0;
}