-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdinh_tru.cpp
More file actions
63 lines (61 loc) · 1.04 KB
/
dinh_tru.cpp
File metadata and controls
63 lines (61 loc) · 1.04 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
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[1001];
bool visited[1001];
int n, m;
void nhap()
{
cin >> n >> m;
for(int i = 1; i <= m; i++)
{
int x, y; cin >> x >> y;
adj[x].push_back(y);
adj[y].push_back(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();
//dem so luong tplt ban dau
int cnt = 0;
for(int i = 1; i <= n; i++)
{
if(!visited[i])
{
cnt++;
DFS(i);
}
}
int res = 0;
for(int i = 1; i <= n; i++)
{
memset(visited, false, sizeof(visited));
visited[i] = true;
int dem = 0;
for(int j = 1; j <= n; j++)
{
if(!visited[j])
{
dem++;
DFS(j);
}
}
if(dem > cnt)
{
res++;
}
}
cout << res << endl;
}