-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha59_q3_cycle.cpp
More file actions
46 lines (36 loc) · 808 Bytes
/
Copy patha59_q3_cycle.cpp
File metadata and controls
46 lines (36 loc) · 808 Bytes
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
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 5;
vector <int> graph[MAX_N];
int degree[MAX_N];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int u, v;
cin >> u >> v;
graph[u].push_back(v);
graph[v].push_back(u);
degree[u]++;
degree[v]++;
}
queue <int> q;
for (int i = 0; i < n; i++) {
if (degree[i] == 1) q.push(i);
}
while (!q.empty()) {
int u = q.front();
q.pop();
for (auto v : graph[u]) {
degree[u]--;
if (--degree[v] == 1) q.push(v);
}
}
int ans = 0;
for (int i = 0; i < n; i++) {
if (degree[i] > 1) ans++;
}
cout << ans;
return 0;
}