Submission #689315

# Submission time Handle Problem Language Result Execution time Memory
689315 2023-01-28T06:48:44 Z zeroesandones Joker (BOI20_joker) C++17
0 / 100
2000 ms 6520 KB
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> pi;

#define FOR(i, j, k) for (ll i = j; i < (ll) k; ++i)
#define FORD(i, j, k) for (ll i = j; i >= (ll) k; --i)
#define nl "\n"
#define sp " "

#define all(x) (x).begin(), (x).end()
#define sc second
#define fr first
#define pb emplace_back

struct UFDS {
    vi link, sz, len;
    int n;

    UFDS(int N) {
        init(N);
    }

    void init(int N) {
        n = N;
        link = vi(n);
        iota(all(link), 0);
        sz = vi(n, 1);
        len = vi(n, 0);
    }

    pi find(ll x) {
        if(link[x] == x)
            return {x, 0};
        pi val = find(link[x]);
        link[x] = val.fr;
        len[x] = (len[x] + val.sc) % 2;
        return {link[x], len[x]};
    }

    void unite(ll a, ll b) {
        pi A = find(a);
        pi B = find(b);
        if(A.fr == B.fr) return;
        if(sz[A.fr] < sz[B.fr]) swap(A, B);

        link[B.fr] = A.fr;
        len[B.fr] = (1 + A.sc + B.sc) % 2;
        sz[A.fr] += sz[B.fr];
    }

    bool same(ll a, ll b){
        return (find(a) == find(b));
    }
};

void solve()
{
    ll n, m, q;
    cin >> n >> m >> q;

    vector<pi> e(m + 1);
    FOR(i, 1, m + 1) {
        cin >> e[i].fr >> e[i].sc;
    }

    UFDS uf(n + 1);
    uf.init(n + 1);

    while(q--) {
        int l, r;
        cin >> l >> r;
        bool cyc = false;
        FOR(i, 1, m + 1) {
            if(l <= i && i <= r) continue;
            if(uf.same(e[i].fr, e[i].sc)) {
                pi A = uf.find(e[i].fr);
                pi B = uf.find(e[i].sc);
                if(A.sc == B.sc) {
                    cyc = true;
                    break;
                }
            } else {
                uf.unite(e[i].fr, e[i].sc);
            }
        }

        cout << (cyc ? "YES" : "NO") << nl;
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Execution timed out 2085 ms 6520 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -