Submission #1049658

# Submission time Handle Problem Language Result Execution time Memory
1049658 2024-08-09T03:39:24 Z shiomusubi496 Joker (BOI20_joker) C++17
14 / 100
2000 ms 18740 KB
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); --i)
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)

using namespace std;

using ll = long long;

template<class T, class U> bool chmin(T& a, const U& b) { return a > b ? a = b, true : false; }
template<class T, class U> bool chmax(T& a, const U& b) { return a < b ? a = b, true : false; }

class UndoableUF {
    vector<int> par;
    vector<pair<int, int>> history;

public:
    UndoableUF(int n) : par(n, -1) {}
    int find(int x) { return par[x] < 0 ? x : find(par[x]); }
    bool merge(int x, int y) {
        x = find(x), y = find(y);
        history.emplace_back(x, par[x]);
        history.emplace_back(y, par[y]);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    bool same(int x, int y) { return find(x) == find(y); }
    void undo() {
        auto [x, px] = history.back(); history.pop_back();
        auto [y, py] = history.back(); history.pop_back();
        par[x] = px;
        par[y] = py;
    }
    void snapshot() { history.clear(); }
    void rollback() {
        while (!history.empty()) undo();
    }
};

int main() {
    int N, M, Q; cin >> N >> M >> Q;
    vector<pair<int, int>> A(M);
    rep (i, M) {
        cin >> A[i].first >> A[i].second;
        --A[i].first, --A[i].second;
    }
    rep (_, Q) {
        UndoableUF uf(2 * N);
        int l, r; cin >> l >> r;
        --l;
        bool f = false;
        rep (i, M) {
            if (l <= i && i < r) continue;
            uf.merge(A[i].first, A[i].second + N);
            uf.merge(A[i].first + N, A[i].second);
            if (uf.same(A[i].first, A[i].first + N)) f = true;
        }
        if (f) puts("YES");
        else puts("NO");
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 28 ms 528 KB Output is correct
30 Correct 75 ms 348 KB Output is correct
31 Correct 52 ms 348 KB Output is correct
32 Correct 44 ms 348 KB Output is correct
33 Correct 45 ms 344 KB Output is correct
34 Correct 47 ms 596 KB Output is correct
35 Correct 52 ms 348 KB Output is correct
36 Correct 42 ms 348 KB Output is correct
37 Correct 65 ms 572 KB Output is correct
38 Correct 61 ms 348 KB Output is correct
39 Correct 42 ms 344 KB Output is correct
40 Correct 44 ms 348 KB Output is correct
41 Correct 44 ms 348 KB Output is correct
42 Correct 42 ms 344 KB Output is correct
43 Correct 67 ms 344 KB Output is correct
44 Correct 107 ms 568 KB Output is correct
45 Correct 69 ms 344 KB Output is correct
46 Correct 59 ms 344 KB Output is correct
47 Correct 44 ms 344 KB Output is correct
48 Correct 44 ms 588 KB Output is correct
49 Correct 45 ms 344 KB Output is correct
50 Correct 90 ms 348 KB Output is correct
51 Correct 44 ms 348 KB Output is correct
52 Correct 67 ms 348 KB Output is correct
53 Correct 75 ms 568 KB Output is correct
54 Correct 50 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Execution timed out 2098 ms 18740 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Execution timed out 2098 ms 18740 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 28 ms 528 KB Output is correct
30 Correct 75 ms 348 KB Output is correct
31 Correct 52 ms 348 KB Output is correct
32 Correct 44 ms 348 KB Output is correct
33 Correct 45 ms 344 KB Output is correct
34 Correct 47 ms 596 KB Output is correct
35 Correct 52 ms 348 KB Output is correct
36 Correct 42 ms 348 KB Output is correct
37 Correct 65 ms 572 KB Output is correct
38 Correct 61 ms 348 KB Output is correct
39 Correct 42 ms 344 KB Output is correct
40 Correct 44 ms 348 KB Output is correct
41 Correct 44 ms 348 KB Output is correct
42 Correct 42 ms 344 KB Output is correct
43 Correct 67 ms 344 KB Output is correct
44 Correct 107 ms 568 KB Output is correct
45 Correct 69 ms 344 KB Output is correct
46 Correct 59 ms 344 KB Output is correct
47 Correct 44 ms 344 KB Output is correct
48 Correct 44 ms 588 KB Output is correct
49 Correct 45 ms 344 KB Output is correct
50 Correct 90 ms 348 KB Output is correct
51 Correct 44 ms 348 KB Output is correct
52 Correct 67 ms 348 KB Output is correct
53 Correct 75 ms 568 KB Output is correct
54 Correct 50 ms 344 KB Output is correct
55 Execution timed out 2050 ms 17984 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 28 ms 528 KB Output is correct
30 Correct 75 ms 348 KB Output is correct
31 Correct 52 ms 348 KB Output is correct
32 Correct 44 ms 348 KB Output is correct
33 Correct 45 ms 344 KB Output is correct
34 Correct 47 ms 596 KB Output is correct
35 Correct 52 ms 348 KB Output is correct
36 Correct 42 ms 348 KB Output is correct
37 Correct 65 ms 572 KB Output is correct
38 Correct 61 ms 348 KB Output is correct
39 Correct 42 ms 344 KB Output is correct
40 Correct 44 ms 348 KB Output is correct
41 Correct 44 ms 348 KB Output is correct
42 Correct 42 ms 344 KB Output is correct
43 Correct 67 ms 344 KB Output is correct
44 Correct 107 ms 568 KB Output is correct
45 Correct 69 ms 344 KB Output is correct
46 Correct 59 ms 344 KB Output is correct
47 Correct 44 ms 344 KB Output is correct
48 Correct 44 ms 588 KB Output is correct
49 Correct 45 ms 344 KB Output is correct
50 Correct 90 ms 348 KB Output is correct
51 Correct 44 ms 348 KB Output is correct
52 Correct 67 ms 348 KB Output is correct
53 Correct 75 ms 568 KB Output is correct
54 Correct 50 ms 344 KB Output is correct
55 Execution timed out 2098 ms 18740 KB Time limit exceeded
56 Halted 0 ms 0 KB -