Question1)
#include <bits/stdc++.h>
using namespace std;
void dfs(int node, vector<vector<int>>& adj, vector<bool>& visited, int& size) {
visited[node] = true;
size++;
for (int neighbor : adj[node]) {
if (!visited[neighbor]) {
dfs(neighbor, adj, visited, size);
}
}
}
int helper(int n, vector<int> &from, vector<int> &to) {
vector<bool> visited(n, false);
int result = 0;
vector<vector<int>> adj(n);
for(int i=0; i<from.size(); i++){
int u = from[i];
int v = to[i];
adj[u].push_back(v);
adj[v].push_back(u);
}
for (int i = 0; i < n; i++) {
if (!visited[i]) {
int size = 0;
dfs(i, adj, visited, size);
result += ceil(sqrt(size));
}
}
return result;
}
int main() {
int n;
cin >> n;
vector<int> from = {1,1,2,3,7};
vector<int> to = {2,3,4,5,8};
int result = helper(n, from, to);
cout << result << endl;
return 0;
}