Submission #914447

#TimeUsernameProblemLanguageResultExecution timeMemory
914447AmrJoker (BOI20_joker)C++14
41 / 100
871 ms14096 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define S second
#define F first
#define all(x) (x).begin(),(x).end()
#define sz size()
#define Yes cout << "YES" << endl
#define No cout << "NO" << endl
#define pb(x) push_back(x);
#define endl '\n'
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int N=3e5+7;
ll INF=INT_MAX,mod=1e9+7;
int TT=1;
ll power(ll x, unsigned int y)
{
    ll res = 1;
    x = x; // % mod;
    if (x == 0) return 0;
    while (y > 0)
    {
        if (y & 1) res = (res*x)  ; // % mod;
        y = y>>1;
        x = (x*x) ; // % mod;
    }
    return res;
}
pair<ll,ll> p[N];
ll siz[N];
pair<ll,ll> get(ll x)
{
    if(p[x].F==x) return p[x];
    pair<ll,ll> hi = get(p[x].F);
    return p[x] = {hi.F,hi.S^p[x].S};
}
pair<ll,ll> a[N];
ll ans[201];
void solve()
{

    ll n , m, q; cin >> n >> m >> q;

    ll lst = 0;
    ll ho = 199;
    if(n<=5000&&q<=5000&&m<=5000) ho = 5000;

    for(int i = 1; i <= m ; i++) cin >> a[i].F >> a[i].S;
    for(int j = 0; j <= min(m,ho); j++){
        for(int i = 1; i <= n; i++) siz[i] = 1,p[i] = {i,0};
        lst = 0;
        for(int i = 1; i <= j; i++)
        {
            ll x = a[i].F , y = a[i].S;
    pair<ll,ll> paix = get(x);
    pair<ll,ll> paiy = get(y);
    ll xx = paix.F, yy = paiy.F;
   // cout << xx << " " << yy << endl;
    if(xx!=yy)
    {
        bool b = (paix.S==paiy.S);
        if(siz[xx]<siz[yy])
        {
            p[xx] = {yy,b};
            siz[yy]+=siz[xx];

        }
        else
        {
            p[yy] = {xx,b};
            siz[xx]+=siz[yy];
        }
    }
    else
    {
        if(paix.S==paiy.S&&lst==0) {lst = i; break;}
    }
        }
       if(lst!=0) {ans[j] = m+1; continue;}


     lst = 0;
    for(int i = m; i >j; i--)
    {
        ll x = a[i].F , y = a[i].S;
        pair<ll,ll> paix = get(x);
        pair<ll,ll> paiy = get(y);
        ll xx = paix.F, yy = paiy.F;
       // cout << xx << " " << yy << endl;
        if(xx!=yy)
        {
            bool b = (paix.S==paiy.S);
            if(siz[xx]<siz[yy])
            {
                p[xx] = {yy,b};
                siz[yy]+=siz[xx];

            }
            else
            {
                p[yy] = {xx,b};
                siz[xx]+=siz[yy];
            }
        }
        else
        {
            if(paix.S==paiy.S&&lst==0) {lst = i; break;}
        }
    }
   ans[j] = lst;
}
    while(q--)
    {
        ll l, r; cin >> l >> r;
        if(r<ans[l-1])  cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}
int main(){
    //freopen("friday.in","r",stdin);
    //freopen("friday.out","w",stdout);
    fast;
    //cin >> TT;
    while(TT--)
        solve();

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...