Problem: 2049C - MEX Cycle
Language: c++20 

Code 1:
#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;





int mex(int a,int b){

    int less = min(a,b);

    int more = max(a,b);

    for(int i=0;i<=3;i++){

        if(i!=less && i!=more){

            return i;

        }

    }

}

int main(){

    int tests;

    cin>>tests;

    for(int test=0;test<tests;test++){

        int n,x,y;

        cin>>n>>x>>y;

        vector<int> a;

        if(n%2==0){

            for(int i=0;i<n;i++){

                if(i%2==0){

                    a.push_back(0);

                }

                else{

                    a.push_back(1);

                }

            }

        }

        else{

            for(int i=0;i<n-2;i++){

                if(i%2==0){

                    a.push_back(0);

                }

                else{

                    a.push_back(1);

                }

            }

            a.push_back(2);

            a.push_back(1);

        }

        if(a[x-1] == a[y-1]){

            a[x-1] = 2;

            for(int i=0;i<n-1;i++){

                if(i==(x-1))continue;

                if(i==0){

                    a[i] = mex(a[n-1],a[i+1]);

                }

                else{

                    a[i] = mex(a[i-1],a[i+1]);

                }

            }

        }



        for(int i=0;i<n;i++){

            cout<<a[i]<<" ";

        }

        cout<<endl;

        

    }

}

Code 2:
#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;





int mex(int a,int b){

    int less = min(a,b);

    int more = max(a,b);

    for(int i=0;i<=3;i++){

        if(i!=less && i!=more){

            return i;

        }

    }

}

int main(){

    int tests;

    cin>>tests;

    for(int test=0;test<tests;test++){

        int n,x,y;

        cin>>n>>x>>y;

        vector<int> a;

        if(n%2==0){

            for(int i=0;i<n;i++){

                if(i%2==0){

                    a.push_back(0);

                }

                else{

                    a.push_back(1);

                }

            }

        }

        else{

            for(int i=0;i<n-2;i++){

                if(i%2==0){

                    a.push_back(0);

                }

                else{

                    a.push_back(1);

                }

            }

            a.push_back(2);

            a.push_back(1);

        }

        if(a[x-1] == a[y-1]){

            a[x-1] = 2;

            for(int i=0;i<n;i++){

                if(i==(x-1))continue;

                if(i==0){

                    a[i] = mex(a[n-1],a[i+1]);

                }

                else if(i==n-1){

                    a[i] = mex(a[i-1],a[0]);

                }

                else{

                    a[i] = mex(a[i-1],a[i+1]);

                }

            }

            for(int i=0;i<n;i++){

                if(i==(x-1))continue;

                if(i==0){

                    a[i] = mex(a[n-1],a[i+1]);

                }

                else if(i==n-1){

                    a[i] = mex(a[i-1],a[0]);

                }

                else{

                    a[i] = mex(a[i-1],a[i+1]);

                }

            }

        }



        for(int i=0;i<n;i++){

            cout<<a[i]<<" ";

        }

        cout<<endl;

        

    }

}

Answer: 2