Submission #726665

# Submission time Handle Problem Language Result Execution time Memory
726665 2023-04-19T08:44:39 Z Johann Joker (BOI20_joker) C++14
39 / 100
2000 ms 26120 KB
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
#define sz(x) (int)(x).size()

int N, M, Q;
vvpii adj;
vpii E;

bool possible_bfs(int l, int r)
{
    vi color(N, -1);
    queue<int> q;
    for (int v = 0; v < N; ++v)
    {
        if (color[v] != -1)
            continue;
        q.push(v), color[v] = 0;
        while (!q.empty())
        {
            int u = q.front();
            q.pop();
            for (pii e : adj[u])
            {
                if (e.second < l || e.second > r)
                {
                    if (color[e.first] == color[u])
                        return true;
                    if (color[e.first] == -1)
                    {
                        q.push(e.first);
                        color[e.first] = !color[u];
                    }
                }
            }
        }
    }
    return false;
}

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

    cin >> N >> M >> Q;
    adj.resize(N);
    E.resize(M);
    for (int i = 0, a, b; i < M; ++i)
    {
        cin >> a >> b;
        --a, --b;
        adj[a].push_back({b, i}), adj[b].push_back({a, i});
        E[i] = {min(a, b), max(a, b)};
    }

    vvpii Queries(M + 1);
    vi ans(Q);
    for (int i = 0, l, r; i < Q; ++i)
    {
        cin >> l >> r;
        --l, --r; // [l, r] inclusive is blocked
        l = min(M, l), r = min(M, r);
        Queries[l].push_back({r, i});
    }
    for (int l = 0; l < sz(Queries); ++l)
    {
        if (Queries[l].empty())
            continue;
        int bl = l - 1, br = M;
        while (bl < br)
        {
            int m = (bl + br + 1) / 2;
            if (possible_bfs(l, m))
                bl = m;
            else
                br = m - 1;
        }
        for (pii q : Queries[l])
            ans[q.second] = (q.first <= bl);
    }

    for (int a : ans)
        if (a)
            cout << "YES\n";
        else
            cout << "NO\n";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 320 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 3 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 3 ms 324 KB Output is correct
15 Correct 12 ms 340 KB Output is correct
16 Correct 3 ms 296 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 320 KB Output is correct
21 Correct 2 ms 316 KB Output is correct
22 Correct 5 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 316 KB Output is correct
25 Correct 2 ms 320 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 324 KB Output is correct
28 Correct 2 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 320 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 3 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 3 ms 324 KB Output is correct
15 Correct 12 ms 340 KB Output is correct
16 Correct 3 ms 296 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 320 KB Output is correct
21 Correct 2 ms 316 KB Output is correct
22 Correct 5 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 316 KB Output is correct
25 Correct 2 ms 320 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 324 KB Output is correct
28 Correct 2 ms 320 KB Output is correct
29 Correct 255 ms 496 KB Output is correct
30 Correct 178 ms 468 KB Output is correct
31 Correct 128 ms 468 KB Output is correct
32 Correct 93 ms 532 KB Output is correct
33 Correct 24 ms 468 KB Output is correct
34 Correct 199 ms 468 KB Output is correct
35 Correct 197 ms 572 KB Output is correct
36 Correct 89 ms 528 KB Output is correct
37 Correct 959 ms 576 KB Output is correct
38 Correct 504 ms 576 KB Output is correct
39 Correct 242 ms 564 KB Output is correct
40 Correct 61 ms 468 KB Output is correct
41 Correct 71 ms 528 KB Output is correct
42 Correct 61 ms 536 KB Output is correct
43 Correct 49 ms 516 KB Output is correct
44 Correct 81 ms 468 KB Output is correct
45 Correct 119 ms 460 KB Output is correct
46 Correct 198 ms 572 KB Output is correct
47 Correct 97 ms 528 KB Output is correct
48 Correct 114 ms 468 KB Output is correct
49 Correct 145 ms 552 KB Output is correct
50 Correct 162 ms 576 KB Output is correct
51 Correct 58 ms 524 KB Output is correct
52 Correct 85 ms 536 KB Output is correct
53 Correct 124 ms 544 KB Output is correct
54 Correct 196 ms 576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 125 ms 18948 KB Output is correct
4 Correct 466 ms 25632 KB Output is correct
5 Correct 203 ms 25964 KB Output is correct
6 Correct 193 ms 22596 KB Output is correct
7 Correct 157 ms 22592 KB Output is correct
8 Correct 137 ms 20512 KB Output is correct
9 Correct 184 ms 22156 KB Output is correct
10 Correct 325 ms 25768 KB Output is correct
11 Correct 246 ms 22460 KB Output is correct
12 Correct 269 ms 25420 KB Output is correct
13 Correct 119 ms 19368 KB Output is correct
14 Correct 134 ms 21080 KB Output is correct
15 Correct 235 ms 23948 KB Output is correct
16 Correct 324 ms 26120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 320 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 3 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 3 ms 324 KB Output is correct
15 Correct 12 ms 340 KB Output is correct
16 Correct 3 ms 296 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 320 KB Output is correct
21 Correct 2 ms 316 KB Output is correct
22 Correct 5 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 316 KB Output is correct
25 Correct 2 ms 320 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 324 KB Output is correct
28 Correct 2 ms 320 KB Output is correct
29 Correct 125 ms 18948 KB Output is correct
30 Correct 466 ms 25632 KB Output is correct
31 Correct 203 ms 25964 KB Output is correct
32 Correct 193 ms 22596 KB Output is correct
33 Correct 157 ms 22592 KB Output is correct
34 Correct 137 ms 20512 KB Output is correct
35 Correct 184 ms 22156 KB Output is correct
36 Correct 325 ms 25768 KB Output is correct
37 Correct 246 ms 22460 KB Output is correct
38 Correct 269 ms 25420 KB Output is correct
39 Correct 119 ms 19368 KB Output is correct
40 Correct 134 ms 21080 KB Output is correct
41 Correct 235 ms 23948 KB Output is correct
42 Correct 324 ms 26120 KB Output is correct
43 Execution timed out 2049 ms 21308 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 320 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 3 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 3 ms 324 KB Output is correct
15 Correct 12 ms 340 KB Output is correct
16 Correct 3 ms 296 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 320 KB Output is correct
21 Correct 2 ms 316 KB Output is correct
22 Correct 5 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 316 KB Output is correct
25 Correct 2 ms 320 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 324 KB Output is correct
28 Correct 2 ms 320 KB Output is correct
29 Correct 255 ms 496 KB Output is correct
30 Correct 178 ms 468 KB Output is correct
31 Correct 128 ms 468 KB Output is correct
32 Correct 93 ms 532 KB Output is correct
33 Correct 24 ms 468 KB Output is correct
34 Correct 199 ms 468 KB Output is correct
35 Correct 197 ms 572 KB Output is correct
36 Correct 89 ms 528 KB Output is correct
37 Correct 959 ms 576 KB Output is correct
38 Correct 504 ms 576 KB Output is correct
39 Correct 242 ms 564 KB Output is correct
40 Correct 61 ms 468 KB Output is correct
41 Correct 71 ms 528 KB Output is correct
42 Correct 61 ms 536 KB Output is correct
43 Correct 49 ms 516 KB Output is correct
44 Correct 81 ms 468 KB Output is correct
45 Correct 119 ms 460 KB Output is correct
46 Correct 198 ms 572 KB Output is correct
47 Correct 97 ms 528 KB Output is correct
48 Correct 114 ms 468 KB Output is correct
49 Correct 145 ms 552 KB Output is correct
50 Correct 162 ms 576 KB Output is correct
51 Correct 58 ms 524 KB Output is correct
52 Correct 85 ms 536 KB Output is correct
53 Correct 124 ms 544 KB Output is correct
54 Correct 196 ms 576 KB Output is correct
55 Execution timed out 2005 ms 15236 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 320 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 3 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 3 ms 324 KB Output is correct
15 Correct 12 ms 340 KB Output is correct
16 Correct 3 ms 296 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 320 KB Output is correct
21 Correct 2 ms 316 KB Output is correct
22 Correct 5 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 316 KB Output is correct
25 Correct 2 ms 320 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 324 KB Output is correct
28 Correct 2 ms 320 KB Output is correct
29 Correct 255 ms 496 KB Output is correct
30 Correct 178 ms 468 KB Output is correct
31 Correct 128 ms 468 KB Output is correct
32 Correct 93 ms 532 KB Output is correct
33 Correct 24 ms 468 KB Output is correct
34 Correct 199 ms 468 KB Output is correct
35 Correct 197 ms 572 KB Output is correct
36 Correct 89 ms 528 KB Output is correct
37 Correct 959 ms 576 KB Output is correct
38 Correct 504 ms 576 KB Output is correct
39 Correct 242 ms 564 KB Output is correct
40 Correct 61 ms 468 KB Output is correct
41 Correct 71 ms 528 KB Output is correct
42 Correct 61 ms 536 KB Output is correct
43 Correct 49 ms 516 KB Output is correct
44 Correct 81 ms 468 KB Output is correct
45 Correct 119 ms 460 KB Output is correct
46 Correct 198 ms 572 KB Output is correct
47 Correct 97 ms 528 KB Output is correct
48 Correct 114 ms 468 KB Output is correct
49 Correct 145 ms 552 KB Output is correct
50 Correct 162 ms 576 KB Output is correct
51 Correct 58 ms 524 KB Output is correct
52 Correct 85 ms 536 KB Output is correct
53 Correct 124 ms 544 KB Output is correct
54 Correct 196 ms 576 KB Output is correct
55 Correct 125 ms 18948 KB Output is correct
56 Correct 466 ms 25632 KB Output is correct
57 Correct 203 ms 25964 KB Output is correct
58 Correct 193 ms 22596 KB Output is correct
59 Correct 157 ms 22592 KB Output is correct
60 Correct 137 ms 20512 KB Output is correct
61 Correct 184 ms 22156 KB Output is correct
62 Correct 325 ms 25768 KB Output is correct
63 Correct 246 ms 22460 KB Output is correct
64 Correct 269 ms 25420 KB Output is correct
65 Correct 119 ms 19368 KB Output is correct
66 Correct 134 ms 21080 KB Output is correct
67 Correct 235 ms 23948 KB Output is correct
68 Correct 324 ms 26120 KB Output is correct
69 Execution timed out 2049 ms 21308 KB Time limit exceeded
70 Halted 0 ms 0 KB -