Submission #931419

# Submission time Handle Problem Language Result Execution time Memory
931419 2024-02-21T18:33:33 Z qwusha Joker (BOI20_joker) C++17
14 / 100
115 ms 5120 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
typedef long double ld;
const ll inf = 1e9;
const ld eps = 1e-8;
const ll logs = 32;
#include <cmath>
bool ch = 0;
vector<vector<pair<int, int>>> g;
vector<bool> ok;
vector<int> col;

void dfs(int v, int c = 0) {
    col[v] = c;
    for (auto [u, ind] : g[v]) {
        if (!ok[ind]) {
            continue;
        }
        if (col[u] == -1)
            dfs(u, 1 - c);
        else if (col[u] == col[v])
            ch = 1;
    }
}


struct dsu {
    vector<int> par, dist, sz;
    void init(int n) {
        par.resize(n);
        dist.assign(n, 0);
        sz.assign(n, 1);
        for (int i = 0; i < n; i++) {
            par[i] = i;
        }
    }
    int get_par(int v) {
        if (v == par[v])
            return v;
        int ans = get_par(par[v]);
        dist[v] = (dist[v] + dist[par[v]]) % 2;
        par[v] = ans;
        return ans;
    }
    int get_dist(int v) {
        if (v == par[v])
            return 0;
        return (dist[v] + get_dist(par[v])) % 2;
    }
    void union_(int v, int u) {
        int nv = get_par(v);
        int nu = get_par(u);
        if (nv == nu) {
            if (get_dist(v) == get_dist(u))
                ch = 1;
            return;
        }
        if (sz[nu] > sz[nv])
            swap(nv, nu);
        par[nu] = nv;
        dist[nu] = 1;
    }
};


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m, q;
    cin >> n >> m >> q;
    if (n <= 2000 && m <= 2000 && q <= 2000) {
        g.resize(n);
        ok.resize(m, 1);
        col.resize(n);
        for (int i = 0; i < m; i++) {
            int v, u;
            cin >> v >> u;
            g[v - 1].push_back({u - 1, i});
            g[u - 1].push_back({v - 1, i});
        }
        for (int qw = 0; qw < q; qw++) {
            int l, r;
            cin >> l >> r;
            for (int i = 0; i < m; i++) {
                if (l - 1 <= i && i < r)
                    ok[i] = 0;
                else
                    ok[i] = 1;
            }
            for (int i = 0; i < n; i++) {
                col[i] = -1;
            }
            bool check = 0;
            for (int i = 0; i < n; i++) {
                if (col[i] == -1) {
                    ch = 0;
                    dfs(i);
                    if (ch)
                        check = 1;
                }
            }
            if (check) {
                cout << "YES" << '\n';
            } else {
                cout << "NO" << '\n';
            }
        }
    } else {
        vector<pair<int, int>> vert(m);
        for (int i = 0; i < m; i++) {
            int v, u;
            cin >> v >> u;
            vert[i] = {v - 1, u - 1};
        }
        reverse(vert.begin(), vert.end());
        int val = -1;
        dsu dsu;
        dsu.init(n);
        for (int i = 0; i < m; i++) {
            auto [v, u] = vert[i];
            ch = 0;
            dsu.union_(v, u);
            if (ch) {
                val = (m - i);
                break;
            }
        }
        for (int qw = 0; qw < q; qw++) {
            int l, r;
            cin >> l >> r;
            if (r < val)
                cout << "YES" << '\n';
            else
                cout << "NO" << '\n';
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 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 1 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 1 ms 344 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 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 344 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 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 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 1 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 1 ms 344 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 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 344 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 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 45 ms 552 KB Output is correct
30 Correct 107 ms 348 KB Output is correct
31 Correct 104 ms 608 KB Output is correct
32 Correct 83 ms 572 KB Output is correct
33 Correct 68 ms 568 KB Output is correct
34 Correct 115 ms 604 KB Output is correct
35 Correct 114 ms 600 KB Output is correct
36 Correct 33 ms 604 KB Output is correct
37 Correct 60 ms 604 KB Output is correct
38 Correct 50 ms 348 KB Output is correct
39 Correct 78 ms 600 KB Output is correct
40 Correct 72 ms 348 KB Output is correct
41 Correct 72 ms 348 KB Output is correct
42 Correct 73 ms 568 KB Output is correct
43 Correct 56 ms 348 KB Output is correct
44 Correct 71 ms 348 KB Output is correct
45 Correct 86 ms 604 KB Output is correct
46 Correct 90 ms 600 KB Output is correct
47 Correct 70 ms 552 KB Output is correct
48 Correct 77 ms 580 KB Output is correct
49 Correct 93 ms 596 KB Output is correct
50 Correct 104 ms 568 KB Output is correct
51 Correct 71 ms 600 KB Output is correct
52 Correct 83 ms 572 KB Output is correct
53 Correct 96 ms 348 KB Output is correct
54 Correct 114 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 53 ms 4076 KB Output is correct
4 Correct 59 ms 5120 KB Output is correct
5 Incorrect 54 ms 4584 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 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 1 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 1 ms 344 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 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 344 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 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 53 ms 4076 KB Output is correct
30 Correct 59 ms 5120 KB Output is correct
31 Incorrect 54 ms 4584 KB Output isn't correct
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 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 1 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 1 ms 344 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 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 344 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 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 45 ms 552 KB Output is correct
30 Correct 107 ms 348 KB Output is correct
31 Correct 104 ms 608 KB Output is correct
32 Correct 83 ms 572 KB Output is correct
33 Correct 68 ms 568 KB Output is correct
34 Correct 115 ms 604 KB Output is correct
35 Correct 114 ms 600 KB Output is correct
36 Correct 33 ms 604 KB Output is correct
37 Correct 60 ms 604 KB Output is correct
38 Correct 50 ms 348 KB Output is correct
39 Correct 78 ms 600 KB Output is correct
40 Correct 72 ms 348 KB Output is correct
41 Correct 72 ms 348 KB Output is correct
42 Correct 73 ms 568 KB Output is correct
43 Correct 56 ms 348 KB Output is correct
44 Correct 71 ms 348 KB Output is correct
45 Correct 86 ms 604 KB Output is correct
46 Correct 90 ms 600 KB Output is correct
47 Correct 70 ms 552 KB Output is correct
48 Correct 77 ms 580 KB Output is correct
49 Correct 93 ms 596 KB Output is correct
50 Correct 104 ms 568 KB Output is correct
51 Correct 71 ms 600 KB Output is correct
52 Correct 83 ms 572 KB Output is correct
53 Correct 96 ms 348 KB Output is correct
54 Correct 114 ms 600 KB Output is correct
55 Incorrect 26 ms 3408 KB Output isn't correct
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 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 1 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 1 ms 344 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 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 344 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 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 45 ms 552 KB Output is correct
30 Correct 107 ms 348 KB Output is correct
31 Correct 104 ms 608 KB Output is correct
32 Correct 83 ms 572 KB Output is correct
33 Correct 68 ms 568 KB Output is correct
34 Correct 115 ms 604 KB Output is correct
35 Correct 114 ms 600 KB Output is correct
36 Correct 33 ms 604 KB Output is correct
37 Correct 60 ms 604 KB Output is correct
38 Correct 50 ms 348 KB Output is correct
39 Correct 78 ms 600 KB Output is correct
40 Correct 72 ms 348 KB Output is correct
41 Correct 72 ms 348 KB Output is correct
42 Correct 73 ms 568 KB Output is correct
43 Correct 56 ms 348 KB Output is correct
44 Correct 71 ms 348 KB Output is correct
45 Correct 86 ms 604 KB Output is correct
46 Correct 90 ms 600 KB Output is correct
47 Correct 70 ms 552 KB Output is correct
48 Correct 77 ms 580 KB Output is correct
49 Correct 93 ms 596 KB Output is correct
50 Correct 104 ms 568 KB Output is correct
51 Correct 71 ms 600 KB Output is correct
52 Correct 83 ms 572 KB Output is correct
53 Correct 96 ms 348 KB Output is correct
54 Correct 114 ms 600 KB Output is correct
55 Correct 53 ms 4076 KB Output is correct
56 Correct 59 ms 5120 KB Output is correct
57 Incorrect 54 ms 4584 KB Output isn't correct
58 Halted 0 ms 0 KB -