-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcanh_cau.cpp
More file actions
69 lines (66 loc) · 1.17 KB
/
canh_cau.cpp
File metadata and controls
69 lines (66 loc) · 1.17 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <bits/stdc++.h>
using namespace std;
set<int> adj[1001];
bool visited[1001];
vector<pair<int, int>> dscanh;
int n, m;
void nhap()
{
cin >> n >> m;
for(int i = 1; i <= m; i++)
{
int x, y; cin >> x >> y;
dscanh.push_back({x, y});
adj[x].insert(y);
adj[y].insert(x);
}
memset(visited, false, sizeof(visited));
}
void DFS(int u)
{
visited[u] = true;
for(int x : adj[u])
{
if(!visited[x])
{
DFS(x);
}
}
}
int main()
{
nhap();
int cnt = 0;
for(int i = 1; i <= n; i++)
{
if(!visited[i])
{
cnt++;
DFS(i);
}
}
int res = 0;
for(auto it : dscanh)
{
int x = it.first, y = it.second;
adj[x].erase(y);
adj[y].erase(x);
int dem = 0;
memset(visited, false, sizeof(visited));
for(int j = 1; j <= n; j++)
{
if(!visited[j])
{
dem++;
DFS(j);
}
}
if(dem > cnt)
{
res++;
}
adj[x].insert(y);
adj[y].insert(x);
}
cout << res << endl;
}