General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
63368677 Practice:
Zory
97E - 19 C++14 (GCC 6-32) Accepted 498 ms 184724 KB 2019-10-25 11:32:02 2019-10-25 11:32:03
→ Source
//Zory-2019
#include<bits/stdc++.h>
using namespace std;
namespace mine
{
    typedef long long ll;
    #define pr pair<int,int>
    #define FR first
    #define SE second
    #define MP make_pair
    #define PB push_back
    #define vc vector
    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())
    #define bin(x) (1ll<<(x))
    #define GG(x) if(x) {puts("error");exit(666);}
    #define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
    #define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num)
    {
        if(num<0) putchar('-'),num=-num;
        if(num>=10) write(num/10);
        putchar('0'+num%10);
    }
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    template<typename T> void chmax(T &x,const T y) {x=(x>y?x:y);}
    template<typename T> void chmin(T &x,const T y) {x=(x<y?x:y);}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

    const int INF=0x3f3f3f3f;
    const int MOD=1e9+7;
    int mm(const int x){return x>=MOD?x-MOD:x;}
    template<typename T> void add(T &x,const T &y){x=(x+y>=MOD?x+y-MOD:x+y);}
    ll qpower(ll x,ll e,int mod=MOD){ll ans=1;GG(e<0)while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
    ll invm(ll x){return qpower(x,MOD-2);}
    const int N=1e6+10;

    vc<int> tree[N];int tag[N];
    int dep[N],rt[N],ff[N][30];
    int getlca(int x,int y)
    {
        if(dep[x]<dep[y]) swap(x,y);
        fd(i,20,0) if(bin(i)<=dep[x]-dep[y]) x=ff[x][i];
        if(x==y) return x;
        fd(i,20,0) if(ff[x][i]!=ff[y][i]) x=ff[x][i],y=ff[y][i];
        return ff[x][0];
    }
    void pushdown(int x,int fa,int root)
    {
        ff[x][0]=fa;fo(i,1,20) ff[x][i]=ff[ff[x][i-1]][i-1];
        rt[x]=root;tag[x]+=tag[fa];
        for(auto y:tree[x]) pushdown(y,x,root);
    }

    vc<int> vdcc,up[N];
    void work(int rt)
    {
        bool ok=0;
        for(auto x:vdcc) if(x!=rt) for(auto y:up[x]) if((dep[x]-dep[y])%2==0) {ok=1;break;}
        if(ok) for(auto x:vdcc) if(x!=rt) tag[x]=1;
    }
    vc<int> to[N];
    int dfnid,dfn[N],low[N];
    stack<int> sta;bool insta[N];
    void tarjan(int x)
    {
        insta[x]=1;sta.push(x);dfn[x]=low[x]=++dfnid;
        fo(t,0,sz(to[x])-1)
        {
            int y=to[x][t];
            if(!dfn[y])
            {
                tree[x].PB(y);dep[y]=dep[x]+1;
                tarjan(y),chmin(low[x],low[y]);
                if(low[y]>=dfn[x])
                {
                    vdcc.clear();vdcc.PB(x);
                    while(sz(sta))
                    {
                        int tmp=sta.top();sta.pop();insta[tmp]=0;
                        vdcc.PB(tmp);if(tmp==y) break;
                    }work(x);
                }
            }
            else
            {
                chmin(low[x],dfn[y]);
                if(dfn[y]<dfn[x]) up[x].PB(y);
            }
        }
    }
    void main()
    {
        int n=qread(),m=qread();
        fo(i,1,m){int x=qread(),y=qread();to[x].PB(y);to[y].PB(x);}
        fo(i,1,n) if(!dfn[i]) tarjan(i);
        fo(i,1,n) if(!rt[i]) pushdown(i,0,i);
        int q=qread();
        while(q--)
        {
            int x=qread(),y=qread();
            if(rt[x]!=rt[y]) {puts("No");continue;}
            if((dep[x]-dep[y])%2!=0) {puts("Yes");continue;}
            puts(tag[x]+tag[y]-2*tag[getlca(x,y)]>0?"Yes":"No");
        }
    }
};//(ans+MOD)%MOD
signed main()
{
    // freopen("a.in","r",stdin);
    srand(time(0));
    mine::main();
}
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details