#pragma GCC target("avx2")
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <chrono>
#include <random>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <iomanip>
#define ff first
#define ss second
#define ll long long int
#define pb push_back
#define bs ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(var,start,end) for(int var=start;var<end;var++)
#define erep(var,start,end) for(int var=start;var<=end;var++)
#define rrep(var,start,end) for(int var=start;var>=end;var--)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define pci pair<char,int>
#define pll pair<ll,ll>
#define test int t;cin>>t;while(t--)
using namespace std;
/////some functions/////
ll modularExponentiation(ll x,ll n,ll M){
if(n==0)
return 1;
else if(n%2 == 0)
return modularExponentiation((x*x)%M,n/2,M);
return (x*modularExponentiation((x*x)%M,(n-1)/2,M))%M;
}
template<class T>
T power(T n, T p){ if(p==0) return 1; else return power(n,p-1)*n;}
int m;
int root(int arr[],int a ){
while(arr[a]!=a){
a = arr[a];
}
return a;
}
void init(int arr[],int size[],int n){
rep(i,1,n){
arr[i]=i;
size[i]=1;
}
}
void weighted_union(int arr[],int size[],int a,int b){
int r_a = root(arr,a);
int r_b = root(arr,b);
if(size[r_a]+size[r_b] > m) return;
if(size[r_b] >= size[r_a]){
arr[r_a] = arr[r_b];
size[r_b] += size[r_a];
}
else{
arr[r_b] = arr[r_a];
size[r_a] += size[r_b];
}
}
bool find(int arr[],int a,int b){
if(root(arr,a)==root(arr,b)) return true;
return false;
}
void solve(){
//code begins
int n;
cin>>n>>m;
int arr[n+1],size[n+1];
init(arr,size,n+1);
int q;
cin >> q;
while(q--){
char op;
cin >> op;
if(op=='A'){
int x,y;
cin >> x >> y;
if(!find(arr,x,y))
weighted_union(arr,size,x,y);
}
else if(op=='E'){
int x,y;
cin >> x >> y;
if(find(arr,x,y)) cout << "Yes" <<'\n';
else cout << "No" <<'\n';
}
else if(op=='S'){
int x;
cin >> x;
cout << size[root(arr,x)] << '\n';
}
}
}
int main()
{
bs;
solve();
}
#pragma GCC target(“avx2”)
was getting the same error in my code from another problem worked for me by removing this line
Thanks. I’ve stuck to not using pragmas after that.