func_code_string: #include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int N = 1e5 + 5;   int x[N], y[N], n, ans = -1, vis[N];   vector<int> gx[N], gy[N];   void dfs(int k) {     if (vis[k]) return;     vis[k] = 1;     for (auto it : gx[x[k]]) dfs(it);     for (auto it : gy[y[k]]) dfs(it);   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> x[i] >> y[i];       gx[x[i]].push_back(i);       gy[y[i]].push_back(i);     }     for (int i = 1; i <= n; i++) {       if (!vis[i]) {         ans++;         dfs(i);       }     }     cout << ans;     return 0;   }   