Submission #1091391

# Submission time Handle Problem Language Result Execution time Memory
1091391 2024-09-20T18:44:52 Z andrei_iorgulescu Joker (BOI20_joker) C++14
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>

using namespace std;

int n, m, q;
int u[200005], v[200005];
int rmin[200005];

pair<int, int> t[200005];
int sz[200005];
bool bip[200005];
int cnt_bad;
int curi;

struct ura
{
    int tip;///0 pentru p1.first != p2.first, 1 pentru celalalt
    int idx = 0, x = 0, y = 0;
    bool bipant = false;
};

vector<ura> op;

pair<int, int> par(int x)
{
    int s1 = 0;
    while (t[x].first != x)
    {
        s1 += t[x].second;
        x = t[x].first;
    }
    return make_pair(x, s1 % 2);
}

void join(int idx, int x, int y)
{
    //cout << idx << ' ' << x << ' ' << y << endl;
    pair<int,int> p1 = par(x);
    pair<int,int> p2 = par(y);
    x = p1.first;
    y = p2.first;
    //cout << x << ' ' << y << endl;
    if (x != y)
    {
        /*if (sz[x] < sz[y])
        {
            swap(x, y);
            swap(p1, p2);
        }*/
        //cout << "c1" << endl;
        t[y] = {x, (1 + p1.second + p2.second) % 2};
        //sz[x] += sz[y];
        /*ura aux;
        aux.tip = 0;
        aux.idx = idx, aux.x = x, aux.y = y;
        aux.bipant = bip[x];*/
        /*if (bip[x] == false and bip[y] == false){
            cnt_bad--;}
        if (bip[y] == false)
            bip[x] = false;*/
        //op.push_back(aux);
    }
    else
    {
        if (p1.second == p2.second and bip[x] == true)
            cnt_bad++;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> m >> q;
    for (int i = 1; i <= m; i++)
        cin >> u[i] >> v[i];
    for (int i = 1; i <= n; i++)
    {
        t[i] = {i, 0};
        sz[i] = 1;
        bip[i] = true;
    }
    rmin[1] = 1;
    for (int i = m; i >= 1; i--)
    {
        join(i, u[i], v[i]);
        if (cnt_bad != 0)
        {
            rmin[1] = i + 1;
            break;
        }
    }
    for (int i = 1; i <= q; i++)
    {
        int x, y;
        cin >> x >> y;
        if (rmin[x] <= y)
            cout << "YES\n";
        else
            cout << "NO\n";
    }
    return 0;
}

/**
deci teoretic daca bag elementele de la 1 la N, apoi fac two pointers-ul, o sa cam am queue-like undoing pe DSU, pe care tin si ceva de bipartit
**/
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -