➤ Problem Link : FOXLINGS
👉 Hint : edit please
✅ C++ Solution :
#include<bits/stdc++.h> using namespace std; #define ll long long int unordered_map<ll,ll> par; ll find(ll i) { if(par.find(i)==par.end()) return i; return par[i]=find(par[i]); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n,m,x,y,p1,p2; cin>>n>>m; for(int i=1;i<=m;i++) { cin>>x>>y; p1=find(x); p2=find(y); if(p1!=p2) par[p1]=p2; } ll l=par.size(); cout<<n-l<<endl; }
Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook.
😇Happy Learning!!