Submission #1014696

# Submission time Handle Problem Language Result Execution time Memory
1014696 2024-07-05T09:47:19 Z MODDI Joker (BOI20_joker) C++14
39 / 100
2000 ms 22096 KB
#include <bits/stdc++.h>

#pragma GCC target("avx2")
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC optimize("O3")

using namespace std;

#define endl '\n'
#define ll long long
#define all(x) x.begin(), x.end()

const int mxn = 2e5 + 100;

int n, m, q;
int dpt[mxn];

vector<int> g[mxn];
bool visited[mxn], ans;

void dfs(int cur, int par = -1, int d = 0) {
    if (ans) return;
    dpt[cur] = d;
    visited[cur] = 1;
    for (auto x : g[cur]) {
        if (visited[x] && x != par) {
            if (abs(dpt[cur] - dpt[x]) % 2 == 0) {
                ans = 1;
                return;
            }
        }
    }
    for (auto x : g[cur]) {
        if (x != par && !visited[x]) dfs(x, cur, d + 1);
    }
}

vector<pair<int, int>> v, qr;

bool pos(int mid) {
    for (int i = 1; i <= n; i++) g[i].clear(), visited[i] = 0, dpt[i] = 0;
    for (int i = mid; i < m; i++) {
        g[v[i].first].push_back(v[i].second);
        g[v[i].second].push_back(v[i].first);
    }
    ans = 0;
    for (int i = 1; i <= n; i++) {
        if (!visited[i]) dfs(i);
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m >> q;
    v.resize(m);
    qr.resize(q);
    for (int i = 0; i < m; i++) cin >> v[i].first >> v[i].second;
    bool S3 = 1;
    for (int i = 0; i < q; i++) {
        cin >> qr[i].first >> qr[i].second;
        if (qr[i].first != 1) S3 = 0;
    }
    if (S3) {
        int l = -1, r = m;
        while (l + 1 < r) {
            int mid = (l + r) / 2;
            if (pos(mid)) l = mid;
            else r = mid;
        }
        for (int i = 0; i < q; i++) {
            bool ans = (qr[i].second - 1) < l;
            cout << (ans ? "YES" : "NO") << endl;
        }
        return 0;
    }
    else {
        for (int j = 0; j < q; j++) {
            int l = qr[j].first, r = qr[j].second;
            l--;
            r--;
            for (int i = 1; i <= n; i++) {
                g[i].clear();
                visited[i] = 0;
                dpt[i] = 0;
            }
            for (int i = 0; i < l; i++) {
                g[v[i].first].push_back(v[i].second);
                g[v[i].second].push_back(v[i].first);
            }
            for (int i = r + 1; i < m; i++) {
                g[v[i].first].push_back(v[i].second);
                g[v[i].second].push_back(v[i].first);
            }
            ans = 0;
            for (int i = 1; i <= n; i++) {
                if (!visited[i]) dfs(i);
            }
            cout << (ans ? "YES" : "NO") << endl;
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 3 ms 4956 KB Output is correct
8 Correct 3 ms 5164 KB Output is correct
9 Correct 3 ms 4952 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 3 ms 4956 KB Output is correct
12 Correct 3 ms 4952 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 3 ms 4952 KB Output is correct
15 Correct 3 ms 4956 KB Output is correct
16 Correct 3 ms 4956 KB Output is correct
17 Correct 3 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 3 ms 4956 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 3 ms 4956 KB Output is correct
22 Correct 2 ms 5164 KB Output is correct
23 Correct 2 ms 5136 KB Output is correct
24 Correct 2 ms 4956 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 2 ms 4952 KB Output is correct
27 Correct 2 ms 4956 KB Output is correct
28 Correct 3 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 3 ms 4956 KB Output is correct
8 Correct 3 ms 5164 KB Output is correct
9 Correct 3 ms 4952 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 3 ms 4956 KB Output is correct
12 Correct 3 ms 4952 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 3 ms 4952 KB Output is correct
15 Correct 3 ms 4956 KB Output is correct
16 Correct 3 ms 4956 KB Output is correct
17 Correct 3 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 3 ms 4956 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 3 ms 4956 KB Output is correct
22 Correct 2 ms 5164 KB Output is correct
23 Correct 2 ms 5136 KB Output is correct
24 Correct 2 ms 4956 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 2 ms 4952 KB Output is correct
27 Correct 2 ms 4956 KB Output is correct
28 Correct 3 ms 4956 KB Output is correct
29 Correct 46 ms 5212 KB Output is correct
30 Correct 51 ms 5212 KB Output is correct
31 Correct 38 ms 5212 KB Output is correct
32 Correct 24 ms 5284 KB Output is correct
33 Correct 15 ms 5208 KB Output is correct
34 Correct 42 ms 5212 KB Output is correct
35 Correct 53 ms 5208 KB Output is correct
36 Correct 29 ms 5212 KB Output is correct
37 Correct 71 ms 5212 KB Output is correct
38 Correct 65 ms 5208 KB Output is correct
39 Correct 44 ms 5208 KB Output is correct
40 Correct 31 ms 5296 KB Output is correct
41 Correct 30 ms 5296 KB Output is correct
42 Correct 30 ms 5212 KB Output is correct
43 Correct 21 ms 5208 KB Output is correct
44 Correct 25 ms 5208 KB Output is correct
45 Correct 32 ms 5212 KB Output is correct
46 Correct 34 ms 5212 KB Output is correct
47 Correct 31 ms 5284 KB Output is correct
48 Correct 33 ms 5284 KB Output is correct
49 Correct 40 ms 5212 KB Output is correct
50 Correct 54 ms 5284 KB Output is correct
51 Correct 26 ms 5208 KB Output is correct
52 Correct 30 ms 5212 KB Output is correct
53 Correct 41 ms 5296 KB Output is correct
54 Correct 52 ms 5208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 129 ms 21844 KB Output is correct
4 Correct 204 ms 22096 KB Output is correct
5 Correct 79 ms 17236 KB Output is correct
6 Correct 112 ms 17744 KB Output is correct
7 Correct 127 ms 16392 KB Output is correct
8 Correct 133 ms 17252 KB Output is correct
9 Correct 144 ms 17636 KB Output is correct
10 Correct 139 ms 18512 KB Output is correct
11 Correct 104 ms 16976 KB Output is correct
12 Correct 118 ms 18520 KB Output is correct
13 Correct 125 ms 15580 KB Output is correct
14 Correct 133 ms 17764 KB Output is correct
15 Correct 133 ms 18768 KB Output is correct
16 Correct 156 ms 19028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 3 ms 4956 KB Output is correct
8 Correct 3 ms 5164 KB Output is correct
9 Correct 3 ms 4952 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 3 ms 4956 KB Output is correct
12 Correct 3 ms 4952 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 3 ms 4952 KB Output is correct
15 Correct 3 ms 4956 KB Output is correct
16 Correct 3 ms 4956 KB Output is correct
17 Correct 3 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 3 ms 4956 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 3 ms 4956 KB Output is correct
22 Correct 2 ms 5164 KB Output is correct
23 Correct 2 ms 5136 KB Output is correct
24 Correct 2 ms 4956 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 2 ms 4952 KB Output is correct
27 Correct 2 ms 4956 KB Output is correct
28 Correct 3 ms 4956 KB Output is correct
29 Correct 129 ms 21844 KB Output is correct
30 Correct 204 ms 22096 KB Output is correct
31 Correct 79 ms 17236 KB Output is correct
32 Correct 112 ms 17744 KB Output is correct
33 Correct 127 ms 16392 KB Output is correct
34 Correct 133 ms 17252 KB Output is correct
35 Correct 144 ms 17636 KB Output is correct
36 Correct 139 ms 18512 KB Output is correct
37 Correct 104 ms 16976 KB Output is correct
38 Correct 118 ms 18520 KB Output is correct
39 Correct 125 ms 15580 KB Output is correct
40 Correct 133 ms 17764 KB Output is correct
41 Correct 133 ms 18768 KB Output is correct
42 Correct 156 ms 19028 KB Output is correct
43 Execution timed out 2028 ms 19712 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 3 ms 4956 KB Output is correct
8 Correct 3 ms 5164 KB Output is correct
9 Correct 3 ms 4952 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 3 ms 4956 KB Output is correct
12 Correct 3 ms 4952 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 3 ms 4952 KB Output is correct
15 Correct 3 ms 4956 KB Output is correct
16 Correct 3 ms 4956 KB Output is correct
17 Correct 3 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 3 ms 4956 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 3 ms 4956 KB Output is correct
22 Correct 2 ms 5164 KB Output is correct
23 Correct 2 ms 5136 KB Output is correct
24 Correct 2 ms 4956 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 2 ms 4952 KB Output is correct
27 Correct 2 ms 4956 KB Output is correct
28 Correct 3 ms 4956 KB Output is correct
29 Correct 46 ms 5212 KB Output is correct
30 Correct 51 ms 5212 KB Output is correct
31 Correct 38 ms 5212 KB Output is correct
32 Correct 24 ms 5284 KB Output is correct
33 Correct 15 ms 5208 KB Output is correct
34 Correct 42 ms 5212 KB Output is correct
35 Correct 53 ms 5208 KB Output is correct
36 Correct 29 ms 5212 KB Output is correct
37 Correct 71 ms 5212 KB Output is correct
38 Correct 65 ms 5208 KB Output is correct
39 Correct 44 ms 5208 KB Output is correct
40 Correct 31 ms 5296 KB Output is correct
41 Correct 30 ms 5296 KB Output is correct
42 Correct 30 ms 5212 KB Output is correct
43 Correct 21 ms 5208 KB Output is correct
44 Correct 25 ms 5208 KB Output is correct
45 Correct 32 ms 5212 KB Output is correct
46 Correct 34 ms 5212 KB Output is correct
47 Correct 31 ms 5284 KB Output is correct
48 Correct 33 ms 5284 KB Output is correct
49 Correct 40 ms 5212 KB Output is correct
50 Correct 54 ms 5284 KB Output is correct
51 Correct 26 ms 5208 KB Output is correct
52 Correct 30 ms 5212 KB Output is correct
53 Correct 41 ms 5296 KB Output is correct
54 Correct 52 ms 5208 KB Output is correct
55 Execution timed out 2045 ms 20048 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 3 ms 4956 KB Output is correct
8 Correct 3 ms 5164 KB Output is correct
9 Correct 3 ms 4952 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 3 ms 4956 KB Output is correct
12 Correct 3 ms 4952 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 3 ms 4952 KB Output is correct
15 Correct 3 ms 4956 KB Output is correct
16 Correct 3 ms 4956 KB Output is correct
17 Correct 3 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 3 ms 4956 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 3 ms 4956 KB Output is correct
22 Correct 2 ms 5164 KB Output is correct
23 Correct 2 ms 5136 KB Output is correct
24 Correct 2 ms 4956 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 2 ms 4952 KB Output is correct
27 Correct 2 ms 4956 KB Output is correct
28 Correct 3 ms 4956 KB Output is correct
29 Correct 46 ms 5212 KB Output is correct
30 Correct 51 ms 5212 KB Output is correct
31 Correct 38 ms 5212 KB Output is correct
32 Correct 24 ms 5284 KB Output is correct
33 Correct 15 ms 5208 KB Output is correct
34 Correct 42 ms 5212 KB Output is correct
35 Correct 53 ms 5208 KB Output is correct
36 Correct 29 ms 5212 KB Output is correct
37 Correct 71 ms 5212 KB Output is correct
38 Correct 65 ms 5208 KB Output is correct
39 Correct 44 ms 5208 KB Output is correct
40 Correct 31 ms 5296 KB Output is correct
41 Correct 30 ms 5296 KB Output is correct
42 Correct 30 ms 5212 KB Output is correct
43 Correct 21 ms 5208 KB Output is correct
44 Correct 25 ms 5208 KB Output is correct
45 Correct 32 ms 5212 KB Output is correct
46 Correct 34 ms 5212 KB Output is correct
47 Correct 31 ms 5284 KB Output is correct
48 Correct 33 ms 5284 KB Output is correct
49 Correct 40 ms 5212 KB Output is correct
50 Correct 54 ms 5284 KB Output is correct
51 Correct 26 ms 5208 KB Output is correct
52 Correct 30 ms 5212 KB Output is correct
53 Correct 41 ms 5296 KB Output is correct
54 Correct 52 ms 5208 KB Output is correct
55 Correct 129 ms 21844 KB Output is correct
56 Correct 204 ms 22096 KB Output is correct
57 Correct 79 ms 17236 KB Output is correct
58 Correct 112 ms 17744 KB Output is correct
59 Correct 127 ms 16392 KB Output is correct
60 Correct 133 ms 17252 KB Output is correct
61 Correct 144 ms 17636 KB Output is correct
62 Correct 139 ms 18512 KB Output is correct
63 Correct 104 ms 16976 KB Output is correct
64 Correct 118 ms 18520 KB Output is correct
65 Correct 125 ms 15580 KB Output is correct
66 Correct 133 ms 17764 KB Output is correct
67 Correct 133 ms 18768 KB Output is correct
68 Correct 156 ms 19028 KB Output is correct
69 Execution timed out 2028 ms 19712 KB Time limit exceeded
70 Halted 0 ms 0 KB -