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

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

using namespace std;

 

#define int long long 

 

void solve(){

    int n, x, y;

    cin >> n >> x >> y;



    if (n == 3){

        cout << 0 << " " << 1 << " " << 2;

        return;

    }

    if (n == 4){

        if (abs(x - y) == 2){

            for (int i = 1; i <= 4; i++){

                if (i == x) cout << 0;

                else if (i == y) cout << 2;

                else cout << 1;

                cout << " ";

            }

        }

        else {

            cout << 0 << " " << 1 << " " << 0 << " " << 1;

        }

        return;

    }



    vector<int> a(n+1, -1);



    queue<int> q;

    q.push(x);



    while (!q.empty()){

        int cur = q.front();

        q.pop();



        int prv = (cur == 1 ? n : cur-1);

        int nxt = (cur == n ? 1 : cur+1);



        int third = -1;

        if (cur == x) third = y;

        if (cur == y) third = x;



        int ans = 0;

        if (third == -1){

            while (ans == a[prv] || ans == a[nxt]){

                ans++;

            }

        }

        else {

            while (ans == a[prv] || ans == a[nxt] || ans == a[third]){

                ans++;

            }

        }



        a[cur] = ans;

        if (a[prv] == -1) q.push(prv);

        if (a[nxt] == -1) q.push(nxt);

        if (third != -1 && a[third] == -1) q.push(third);

    }



    for (int i = 1; i <= n; i++) cout << a[i] << " ";

}

 

signed main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    int t = 1; 

    cin >> t; 

    while (t--){ 

        solve();

        cout << '\n';

    } 

}

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

using namespace std;

 

#define int long long 

 

void solve(){

    int n, x, y;

    cin >> n >> x >> y;



    if (n == 3){

        cout << 0 << " " << 1 << " " << 2;

        return;

    }

    if (n == 4){

        if (abs(x - y) == 2){

            for (int i = 1; i <= 4; i++){

                if (i == x) cout << 0;

                else if (i == y) cout << 2;

                else cout << 1;

                cout << " ";

            }

        }

        else {

            for (int i = 1; i <= 4; i++){

                if (i == x || i == y) cout << 0;

                else cout << 1;

                cout << " ";

            }

        }

        return;

    }



    vector<int> a(n+1, -1);



    queue<int> q;

    q.push(x);



    while (!q.empty()){

        int cur = q.front();

        q.pop();



        int prv = (cur == 1 ? n : cur-1);

        int nxt = (cur == n ? 1 : cur+1);



        int third = -1;

        if (cur == x) third = y;

        if (cur == y) third = x;



        int ans = 0;

        if (third == -1){

            while (ans == a[prv] || ans == a[nxt]){

                ans++;

            }

        }

        else {

            while (ans == a[prv] || ans == a[nxt] || ans == a[third]){

                ans++;

            }

        }



        a[cur] = ans;

        if (a[prv] == -1) q.push(prv);

        if (a[nxt] == -1) q.push(nxt);

        if (third != -1 && a[third] == -1) q.push(third);

    }



    for (int i = 1; i <= n; i++) cout << a[i] << " ";

}

 

signed main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    int t = 1; 

    cin >> t; 

    while (t--){ 

        solve();

        cout << '\n';

    } 

}

Answer: 1