-
-
Save ArthurLoboLobo/6e4af6bd81b185f9085060cd5de2c7de to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
const int MAXN = 2e5+10; | |
int n, m, c, visitado[MAXN]; | |
vector<int> viz[MAXN]; | |
void dfs(int a) { | |
visitado[a] = 1; | |
for(auto b : viz[a]) { | |
if(visitado[b] == 0) dfs(b); | |
} | |
} | |
int32_t main() { | |
cin >> n >> m; | |
for(int i = 1; i <= m; i++) { | |
int a,b; cin >> a >> b; | |
viz[a].push_back(b); | |
viz[b].push_back(a); | |
} | |
for(int i = 1; i <= n; i++) { | |
if(!visitado[i]) { | |
c++; | |
dfs(i); | |
} | |
} | |
cout << m-n+c << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment