Submission #765252

# Submission time Handle Problem Language Result Execution time Memory
765252 2023-06-24T09:58:35 Z adrilen Joker (BOI20_joker) C++17
0 / 100
86 ms 11148 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> pii;
typedef array<int, 2> arr;
typedef array<int, 3> arrr;

constexpr int maxn = 2e5;

int siz[maxn] = { 0 }, par[maxn] = { 0 }, parity[maxn] = { 0 };
bool cycle[maxn] = { 0 };


int fnd(int p)
{
    if (p == par[p]) return p;
    return fnd(par[p]);
}

int fnd_parity(int p, int pari)
{
    if (p == par[p]) return pari;

    return fnd_parity(par[p], pari ^ parity[par[p]]);
}

bool odd_cycle = false;

void uni(int a, int b)
{
    int aa = fnd(a), bb = fnd(b);

    if (aa == bb) {
        if (fnd_parity(a, parity[a]) == fnd_parity(b, parity[b])) {
            // Odd cycle
            // cout << "\n";
            // cout << a << " " << b << " odd cycle\n";
            cycle[aa] = true;
            odd_cycle = true;
        } else {
            // Not odd cycle
        }
        return ;
    }

    if (siz[aa] > siz[bb]) {
        swap(a, b);
        swap(aa, bb);
    }
    
    // b > a
    parity[aa] = parity[a] ^ parity[b] ^ 1;
    par[aa] = bb;
    siz[bb] += siz[aa];

}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n, m, q;
    cin >> n >> m >> q;

    for (int i = 0; i < n; i++) {
        siz[i] = 1;
        par[i] = i;
    }

    vector<arr> edges(m);
    for (auto &i : edges)
    {
        cin >> i[0] >> i[1];
        i[0]--, i[1]--;
    }
    
    vector<arrr> queries(q);
    for (int i = 0; i< q; i++)
    {

        cin >> queries[i][0] >> queries[i][1];
        queries[i][0]--, queries[i][1]--;
        queries[i][2] = i;
    }
    

    vector <bool> output(q);
 
    reverse(edges.begin(), edges.end());
    sort(queries.begin(), queries.end(), greater<arrr>());

    auto it = queries.begin();

    int a = 0;
    for (auto &i : edges)
    {
        while (it != queries.end() && m - 1 - (*it)[1] == a)
        {
            // cout << (*it)[2] << "\n";
            output[(*it)[2]] = odd_cycle;
            it++;
        }

        uni(i[0], i[1]);


        // cout << a << " " << (odd_cycle ? "YES" : "NO") << "\n";
        a++;
    }


    for (bool i : output) cout << (i ? "YES" : "NO") << "\n";



    // cout << par[0] << "\n";
    // for (int i = 0; i < n; i++) {
    //     cout << parity[i] << " ";
    // }
    // cout << "\n";
    // for (int i = 0; i < n; i++) {
    //     cout << par[i] << " ";
    // }
    // cout << "\n";
    
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 76 ms 6080 KB Output is correct
4 Correct 81 ms 10704 KB Output is correct
5 Incorrect 86 ms 11148 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -