Submission #256014

# Submission time Handle Problem Language Result Execution time Memory
256014 2020-08-02T08:13:10 Z 최은수(#5029) Joker (BOI20_joker) C++17
0 / 100
2 ms 640 KB
#include<iostream>
#include<vector>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18+7;
int pa[200010],pr[200010];
inline pi par(int x)
{
    int y=0;
    int z=x;
    while(pa[z]!=0)
        y^=pr[z],z=pa[z];
    int w=y;
    while(pa[x]!=0)
    {
        int nx=pa[x];
        int nw=w^pr[w];
        pa[x]=z;
        pr[x]=w;
        x=nx;
        w=nw;
    }
    return pi(z,y);
}
inline void uni(int x,int y)
{
    int odd=par(x).se^par(y).se;
    x=par(x).fi;
    y=par(y).fi;
    if(x==y)
        return;
    pa[x]=y;
    pr[x]=odd^1;
    return;
}
inline void clear(int n)
{
    fill(pa,pa+n+1,0);
    return;
}
int ans[200010];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m,q;
    cin>>n>>m>>q;
    vector<pi>edge(m);
    for(pi&t:edge)
        cin>>t.fi>>t.se;
    vector<pi>qv(q);
    vector<int>cv;
    for(pi&t:qv)
        cin>>t.fi>>t.se,cv.eb(--t.fi);
    sort(all(cv));
    cv.erase(unique(all(cv)));
    for(int&cl:cv)
    {
        clear(n);
        ans[cl]=-1;
        for(int i=0;i<cl;i++)
        {
            int u=edge[i].fi,v=edge[i].se;
            if(par(u)==par(v))
            {
                ans[cl]=m;
                break;
            }
            uni(u,v);
        }
        if(ans[cl]!=-1)
            continue;
        for(int i=m;--i>cl;)
        {
            int u=edge[i].fi,v=edge[i].se;
            if(par(u)==par(v))
            {
                ans[cl]=i;
                break;
            }
            uni(u,v);
        }
    }
    for(pi&t:qv)
        cout<<(ans[t.fi]<t.se?"NO\n":"YES\n");
    cout.flush();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -