Submission #765267

# Submission time Handle Problem Language Result Execution time Memory
765267 2023-06-24T10:04:27 Z Hegdahl Joker (BOI20_joker) C++17
14 / 100
2000 ms 5144 KB
#include <bits/stdc++.h>

using namespace std;

struct UnionFind {
  vector<int> parent_or_neg_size, edge_parity;

  UnionFind(int n) : parent_or_neg_size(n, -1), // hver komponent har til å begynne med størrelse 1
                     edge_parity(n, 0) {}

  pair<int, int> find_root_and_parity(int i) {
    int parity = 0;
    while (parent_or_neg_size[i] >= 0) {
      parity ^= edge_parity[i];
      i = parent_or_neg_size[i];
    }
    return {i, parity};
  }

  enum UniteResult { NO_CYCLE, EVEN_CYCLE, ODD_CYCLE };
  UniteResult unite(int i, int j, bool new_edge_parity = true) {
    auto [root_i, parity_i] = find_root_and_parity(i);
    auto [root_j, parity_j] = find_root_and_parity(j);
    if (root_i == root_j) {
      if (parity_i ^ parity_j ^ new_edge_parity) {
        return ODD_CYCLE;
      } else {
        return EVEN_CYCLE;
      }
    }
    if (parent_or_neg_size[root_i] > parent_or_neg_size[root_j]) {
      swap(root_i, root_j);
      swap(parity_i, parity_j);
    }
    parent_or_neg_size[root_i] += parent_or_neg_size[root_j];
    parent_or_neg_size[root_j] = root_i;
    edge_parity[root_j] = parity_i ^ parity_j ^ new_edge_parity;
    return NO_CYCLE;
  }
};

int main() {
  int n, m, q;
  cin >> n >> m >> q;

  vector<array<int, 2>> edges(m);
  for (auto &[u, v] : edges) {
    cin >> u >> v;
    --u;
    --v;
  }

  while (q--) {
    int l, r;
    cin >> l >> r;
    --l;

    UnionFind uf(n);
    bool odd = false;
    for (int j = 0; j < l; ++j) {
      auto [u, v] = edges[j];
      if (uf.unite(u, v) == UnionFind::ODD_CYCLE) {
        odd = true;
        break;
      }
    }

    for (int j = r; j < m; ++j) {
      auto [u, v] = edges[j];
      if (uf.unite(u, v) == UnionFind::ODD_CYCLE) {
        odd = true;
        break;
      }
    }

    cout << (odd ? "YES" : "NO") << '\n';
  }
}

# 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 296 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 1 ms 296 KB Output is correct
17 Correct 1 ms 296 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 304 KB Output is correct
22 Correct 1 ms 300 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 296 KB Output is correct
26 Correct 1 ms 296 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 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 296 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 1 ms 296 KB Output is correct
17 Correct 1 ms 296 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 304 KB Output is correct
22 Correct 1 ms 300 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 296 KB Output is correct
26 Correct 1 ms 296 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 11 ms 356 KB Output is correct
30 Correct 15 ms 340 KB Output is correct
31 Correct 12 ms 340 KB Output is correct
32 Correct 11 ms 340 KB Output is correct
33 Correct 7 ms 340 KB Output is correct
34 Correct 12 ms 348 KB Output is correct
35 Correct 15 ms 336 KB Output is correct
36 Correct 10 ms 340 KB Output is correct
37 Correct 15 ms 304 KB Output is correct
38 Correct 19 ms 340 KB Output is correct
39 Correct 17 ms 368 KB Output is correct
40 Correct 12 ms 364 KB Output is correct
41 Correct 10 ms 340 KB Output is correct
42 Correct 10 ms 344 KB Output is correct
43 Correct 17 ms 360 KB Output is correct
44 Correct 16 ms 312 KB Output is correct
45 Correct 15 ms 340 KB Output is correct
46 Correct 17 ms 376 KB Output is correct
47 Correct 12 ms 356 KB Output is correct
48 Correct 17 ms 280 KB Output is correct
49 Correct 13 ms 364 KB Output is correct
50 Correct 17 ms 348 KB Output is correct
51 Correct 12 ms 316 KB Output is correct
52 Correct 13 ms 372 KB Output is correct
53 Correct 13 ms 340 KB Output is correct
54 Correct 18 ms 368 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 Execution timed out 2053 ms 3140 KB Time limit exceeded
4 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 296 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 1 ms 296 KB Output is correct
17 Correct 1 ms 296 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 304 KB Output is correct
22 Correct 1 ms 300 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 296 KB Output is correct
26 Correct 1 ms 296 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Execution timed out 2053 ms 3140 KB Time limit exceeded
30 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 296 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 1 ms 296 KB Output is correct
17 Correct 1 ms 296 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 304 KB Output is correct
22 Correct 1 ms 300 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 296 KB Output is correct
26 Correct 1 ms 296 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 11 ms 356 KB Output is correct
30 Correct 15 ms 340 KB Output is correct
31 Correct 12 ms 340 KB Output is correct
32 Correct 11 ms 340 KB Output is correct
33 Correct 7 ms 340 KB Output is correct
34 Correct 12 ms 348 KB Output is correct
35 Correct 15 ms 336 KB Output is correct
36 Correct 10 ms 340 KB Output is correct
37 Correct 15 ms 304 KB Output is correct
38 Correct 19 ms 340 KB Output is correct
39 Correct 17 ms 368 KB Output is correct
40 Correct 12 ms 364 KB Output is correct
41 Correct 10 ms 340 KB Output is correct
42 Correct 10 ms 344 KB Output is correct
43 Correct 17 ms 360 KB Output is correct
44 Correct 16 ms 312 KB Output is correct
45 Correct 15 ms 340 KB Output is correct
46 Correct 17 ms 376 KB Output is correct
47 Correct 12 ms 356 KB Output is correct
48 Correct 17 ms 280 KB Output is correct
49 Correct 13 ms 364 KB Output is correct
50 Correct 17 ms 348 KB Output is correct
51 Correct 12 ms 316 KB Output is correct
52 Correct 13 ms 372 KB Output is correct
53 Correct 13 ms 340 KB Output is correct
54 Correct 18 ms 368 KB Output is correct
55 Execution timed out 2049 ms 5144 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 296 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 1 ms 296 KB Output is correct
17 Correct 1 ms 296 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 304 KB Output is correct
22 Correct 1 ms 300 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 296 KB Output is correct
26 Correct 1 ms 296 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 11 ms 356 KB Output is correct
30 Correct 15 ms 340 KB Output is correct
31 Correct 12 ms 340 KB Output is correct
32 Correct 11 ms 340 KB Output is correct
33 Correct 7 ms 340 KB Output is correct
34 Correct 12 ms 348 KB Output is correct
35 Correct 15 ms 336 KB Output is correct
36 Correct 10 ms 340 KB Output is correct
37 Correct 15 ms 304 KB Output is correct
38 Correct 19 ms 340 KB Output is correct
39 Correct 17 ms 368 KB Output is correct
40 Correct 12 ms 364 KB Output is correct
41 Correct 10 ms 340 KB Output is correct
42 Correct 10 ms 344 KB Output is correct
43 Correct 17 ms 360 KB Output is correct
44 Correct 16 ms 312 KB Output is correct
45 Correct 15 ms 340 KB Output is correct
46 Correct 17 ms 376 KB Output is correct
47 Correct 12 ms 356 KB Output is correct
48 Correct 17 ms 280 KB Output is correct
49 Correct 13 ms 364 KB Output is correct
50 Correct 17 ms 348 KB Output is correct
51 Correct 12 ms 316 KB Output is correct
52 Correct 13 ms 372 KB Output is correct
53 Correct 13 ms 340 KB Output is correct
54 Correct 18 ms 368 KB Output is correct
55 Execution timed out 2053 ms 3140 KB Time limit exceeded
56 Halted 0 ms 0 KB -