-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate.cpp
More file actions
40 lines (40 loc) · 737 Bytes
/
create.cpp
File metadata and controls
40 lines (40 loc) · 737 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
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
vector<ll> adj[100009];
ll vis[100009] = {0};
ll has_cycle;
void dfs(ll i, ll p)
{
vis[i] = 1;
for (ll x : adj[i])
{
if (vis[x] == 0)
dfs(x, i);
else if (vis[x] == 1 and x != p)
has_cycle = 1;
}
}
int main()
{
ll n, m, x, y, ans = 0;
cin >> n >> m;
for (ll i = 1; i <= m; i++)
{
cin >> x >> y;
adj[x].push_back(y);
adj[y].push_back(x);
}
for (ll i = 1; i <= n; i++)
{
if (vis[i] == 0)
{
has_cycle = 0;
dfs(i, i);
if (has_cycle == 0)
ans++;
}
}
cout << ans;
}