Language: C++

#include <bits/stdc++.h>

#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define an size()

using namespace std;

const ll maxn=1e4+900;
ll x[maxn][2];
set<pair<ll,ll> > st;
char viz[maxn];
ll m;
stack<ll> tagh;
bool bfs(ll a)
{
    set<pair<ll,ll> > ::iterator it,itt;
    it=st.lower_bound(mp(x[a][viz[a]-1]-m,0));
    itt=st.lower_bound(mp(x[a][viz[a]-1]+m+1,0));
    stack<ll> sttk;
    ll u,j,er,ew;
    pair<ll,ll> ity;
    if (itt!=st.end())
    {
        ity=*itt;
    }
    else
    {
        ity=mp(1e10,1e10);
    }
    while ((*it).F<ity.F && it!=st.end() )
    {
        u=(*it).S;
        j=(*it).F;
        it++;
        if (u!=a)
        {
            if (x[u][0]==j)
            {
                ew=1;
                er=u;
                if (viz[er]==ew)
                {
                    return 0;
                }
                if (viz[er]==0)
                {
                    viz[er]=-ew+3;
                    tagh.persh(er);
                    sttk.persh(er);
                }
            }
            if (x[u][1]==j)
            {
                ew=2;
                er=u;
                if (viz[er]==ew)
                {
                    return 0;
                }
                if (viz[er]==0)
                {
                    viz[er]=-ew+3;
                    tagh.persh(er);
                    sttk.persh(er);
                }
            }
        }
    }
    while (!sttk.empty())
    {
        if (bfs(sttk.top())==0)
        {
            return 0;
        }
        sttk.pop();
    }
    return 1;
}

int main()
{
    ll n;
    cin>>n;
    for (ll i=0; i<n; i++)
    {
        cin>>x[i][0]>>x[i][1];
        st.insert(mp(x[i][0],i));
        st.insert(mp(x[i][1],i));
    }
    ll s=0;
    ll t=1e9+900;




    /////////////////
    m=0;
    for (ll i=0; i<n; i++)
    {
        if (viz[i]==0)
        {
            viz[i]=rand()%2+1;
            if (!bfs(i))
            {
                while (!tagh.empty())
                {
                    viz[tagh.top()]=0;
                    tagh.pop();
                }
                viz[i]=-1*viz[i]+3;
                if (!bfs(i))
                {
                    cout<<0;
                    return 0;
                }
            }
            while (!tagh.empty())
            {
                tagh.pop();
            }
        }
    }

/////////////

    while (t-s>1)
    {
        m=s+t;
        m/=2;
        memset(viz,0,maxn);
        bool ok=1;
        for (ll i=n-1; i>=0; i--)
        {
            if (viz[i]==0)
            {
                viz[i]=rand()%2+1;
                if (!bfs(i))
                {
                    while (!tagh.empty())
                    {
                        viz[tagh.top()]=0;
                        tagh.pop();
                    }
                    viz[i]=-1*viz[i]+3;
                    if (!bfs(i))
                    {
                        ok=0;
                        break;
                    }
                }
                while (!tagh.empty())
                {
                    tagh.pop();
                }
            }
        }
        if (ok)
        {
            s=m;
        }
        else
        {
            t=m;
        }
    }

    cout<<s+1;
}


Compiler output:
a.cc: In function 'bool bfs(long long int)':
a.cc:52:26: error: 'class std::stack<long long int>' has no member named 'persh'
   52 |                     tagh.persh(er);
      |                          ^~~~~
a.cc:53:26: error: 'class std::stack<long long int>' has no member named 'persh'
   53 |                     sttk.persh(er);
      |                          ^~~~~
a.cc:67:26: error: 'class std::stack<long long int>' has no member named 'persh'
   67 |                     tagh.persh(er);
      |                          ^~~~~
a.cc:68:26: error: 'class std::stack<long long int>' has no member named 'persh'
   68 |                     sttk.persh(er);
      |                          ^~~~~