-
-
Save ArthurLoboLobo/87fc5c6ac2df3db5e6a2bffec183ccb3 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 = 1e5+10; | |
int n, r, k, visitado[MAXN]; | |
vector<int> viz[MAXN]; | |
int quantidade = 0; | |
void dfs(int a) { | |
quantidade++; | |
visitado[a] = 1; | |
for(auto b : viz[a]) { | |
if(visitado[b] == 0) dfs(b); | |
} | |
} | |
int main() { | |
cin >> n >> r >> k; | |
for(int i = 1; i <= r; i++) { | |
int a,b; | |
cin >> a >> b; | |
viz[a].push_back(b); | |
viz[b].push_back(a); | |
} | |
int resposta = 0; | |
for(int i = 1; i <= n; i++) { | |
if(visitado[i] == 0) { | |
quantidade = 0; | |
dfs(i); | |
resposta+= ceil((float) quantidade/k); | |
} | |
} | |
cout << resposta << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment