Submission #765265

# Submission time Handle Problem Language Result Execution time Memory
765265 2023-06-24T10:03:19 Z canadavid1 Joker (BOI20_joker) C++14
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>


using namespace std;

vector<bool> diff;
vector<int> p;
vector<int> siz;

pair<int,bool> find(int a,bool len=0)
{
    if (p[a] == -1) return {a,len};
    return find(p[a],len^diff[a]); // no path compression
}

bool unite(int a,int b) // true if works, false elsewise
{
    auto av = find(a);
    auto bv = find(b);
    if (av.first == bv.first) return av.second!=bv.second;
    
    if (siz[av.first] > siz[bv.first]) swap(av,bv);
    // b > a
    p[av.first] = bv.first;
    siz[bv.first] += siz[av.first];
    if (av.second == bv.second) diff[av.first] = true;
    return true;
}


vector<pair<int,int>> edge;
vector<pair<int,int>> query;
vector<bool> queryvalid;
int N,M,Q,added;
int main()
{
    cin >> N >> M >> Q;
    diff.assign(N+1,false);
    p.assign(N+1,-1);
    siz.assign(N+1,1);
    queryvalid.assign(Q,false);
    edge.push_back({0,0});
    for(int i = 0; i < M; i++)
    {
        int l,r;
        cin >> l >> r;
        edge.push_back({l,r});     
    }
    for(int i = 0; i < Q; i++)
    {
        int l,r;
        cin >> l >> r;
        query.push_back({r,i});
    }
    sort(query.begin(),query.end());
    added = M;
    bool valid = true;
    while(query.size())
    {
        for(;added>query.back().first;added--)
        {
            valid &= unite(edge[added].first,edge[added].second);
        }
        queryvalid[query.back().second] = valid;
        query.pop_back();
    }
    for (auto &&i : queryvalid)
    {
        cout << (i ? "YES\n" : "NO\n");
    }

/*
    vector<vector<int>> neigh(N+1);
    vector<pair<int,int>> edge;
    for(int i = 0; i < N; i++)
    {
        int u,v;
        cin >> u >> v;
        neigh[u].push_back(v);
        neigh[v].push_back(u);
        edge.push_back({u,v});
    }
    vector<pair<int,int>> query(Q);
    int l;
    for (auto &&r : query) cin >> l >> r.first;
    for(int i = 0; i < Q; i++) query[i].second = i;
    sort(query.begin(),query.end());
    vector<bool> result;
    int s;
    while(query.size())
    {

    }*/
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -