Advertisement
NgJaBach

DSU

Jan 8th, 2022
1,081
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 KB | None
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4. typedef long long int ll;
  5. //#define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
  6. #define pb push_back
  7. #define mp make_pair
  8. #define fi first
  9. #define se second
  10. #define gcd __gcd
  11. #define getl(s) getline(cin, s);
  12. #define setpre(x) fixed << setprecision(x)
  13. #define mset(a) memset(a, 0, sizeof(a))
  14. #define endl '\n'
  15. const int N=200050,M=1000000007;
  16. const ll INF=1e18+7;
  17. int cha[N],cha_size[N];
  18. int find_cha(int u){
  19.     if(cha[u]==u) return u;
  20.     return cha[u]=find_cha(cha[u]);
  21. }
  22. void European_Union(int u,int v){
  23.     int a,b;
  24.     a=find_cha(u);
  25.     b=find_cha(v);
  26.     if(cha_size[a]<cha_size[b]) swap(a,b);
  27.     cha[b]=a;
  28.     cha_size[a]+=cha_size[b];
  29.     return;
  30. }
  31. int main(){
  32.     ios_base::sync_with_stdio(NULL); cin.tie(nullptr); cout.tie(nullptr);
  33. //    freopen(".inp","r",stdin);
  34. //    freopen(".out","w",stdout);
  35.     int n;
  36.     cin>>n;
  37.     for(int i=1;i<=n;++i){
  38.         cha[i]=i;
  39.         cha_size[i]=1;
  40.     }
  41.     return 0;
  42. }
  43. /*
  44. ==================================+
  45. INPUT:                            |
  46. ------------------------------    |
  47.  
  48. ------------------------------    |
  49. ==================================+
  50. OUTPUT:                           |
  51. ------------------------------    |
  52.  
  53. ------------------------------    |
  54. ==================================+
  55. */
Advertisement
RAW Paste Data Copied
Advertisement