Skip to content

Instantly share code, notes, and snippets.

@ArthurLoboLobo
Created March 26, 2023 01:23
Show Gist options
  • Save ArthurLoboLobo/87fc5c6ac2df3db5e6a2bffec183ccb3 to your computer and use it in GitHub Desktop.
Save ArthurLoboLobo/87fc5c6ac2df3db5e6a2bffec183ccb3 to your computer and use it in GitHub Desktop.
#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