-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNo More Cycles.cpp
More file actions
52 lines (48 loc) · 850 Bytes
/
No More Cycles.cpp
File metadata and controls
52 lines (48 loc) · 850 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
47
48
49
50
51
52
#include<iostream>
#include<vector>
#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
#define pb push_back
#define mk make_pair
#define fastio ios_base::sync_with_stdio(false); cout.tie(NULL);
using namespace std;
vector<int> ar[100001],con_comp;
int cc,vis[100001];
void DFS(int src)
{
vis[src]=1;
for(auto el : ar[src])
{
if(vis[el]==0)
{
con_comp.pb(el);
cc++;
DFS(el);
}
}
}
int main()
{
fastio;
int n,m,a,b,i,ans=0;
cin>>n>>m;
for(i=0;i<m;i++)
cin>>a>>b , ar[a].pb(b) , ar[b].pb(a);
for(i=1;i<=n;i++)
{
if(vis[i]==0)
{
cc=1;
con_comp.pb(i);
DFS(i);
int total_edges=0;
for(auto el : con_comp)
total_edges+=ar[el].size();
con_comp.clear();
ans+=max(0,(total_edges/2)-(cc-1));
}
}
cout<<ans;
return 0;
}