Submission #599329

# Submission time Handle Problem Language Result Execution time Memory
599329 2022-07-19T12:44:55 Z OttoTheDino Joker (BOI20_joker) C++17
0 / 100
2000 ms 8280 KB
#include<bits/stdc++.h>
using namespace std;

#define rep(i,s,e)                          for (int i = s; i <= e; ++i)
#define rrep(i,s,e)                         for (int i = s; i >= e; --i)
#define fi                                  first
#define se                                  second
#define pb                                  push_back
typedef vector<int> vi;
typedef pair<int,int> ii;

const int mx = 2e5;
vi adj[mx+1];

int par[mx+1], h[mx+1], tp[mx+1];

ii get_par (int u) {
    if (u==par[u]) return {u, tp[u]};
    ii res = get_par (par[u]); 
    return {res.fi, res.se^tp[u]};
}

void merge (int u, int v) {
    ii paru = get_par(u), parv = get_par(v);
    if (h[paru.fi]<h[parv.fi]) swap(paru, parv);
    h[paru.fi] += h[paru.fi]==h[parv.fi];
    par[parv.fi] = paru.fi; 
    tp[parv.fi] ^= parv.se==paru.se;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n, m, q; cin >>n >> m >> q;

    ii e[m+1];
    rep (i,1,m) cin >> e[i].fi >> e[i].se;

    while (q--) {
        int l, r; cin >> l >> r;
        bool got = 0;
        rep (j,1,n) {
            par[j] = j;
            h[j] = 1;
            tp[j] = 0;
        }
        rep (j,1,l) {
            ii parj = get_par(e[j].fi), parv = get_par(e[j].se);
            if (parj.fi==parv.fi) got |= (parj.se==parv.se);
            else merge(e[j].fi,e[j].se);
        }
        rrep (j,m,r) {
            ii parj = get_par(e[j].fi), parv = get_par(e[j].se);
            if (parj.fi==parv.fi) got |= (parj.se==parv.se);
            else merge(e[j].fi,e[j].se);
        }
        if (got>r) cout << "YES\n";
        else cout << "NO\n";
    }



    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Incorrect 3 ms 4948 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Incorrect 3 ms 4948 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Execution timed out 2035 ms 8280 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Incorrect 3 ms 4948 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Incorrect 3 ms 4948 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Incorrect 3 ms 4948 KB Output isn't correct
4 Halted 0 ms 0 KB -