Submission #606653

# Submission time Handle Problem Language Result Execution time Memory
606653 2022-07-26T07:36:45 Z piOOE Highway Tolls (IOI18_highway) C++17
100 / 100
282 ms 11256 KB
#include <bits/stdc++.h>
#include "highway.h"

using namespace std;

using ll = long long;

void find_pair(int n, vector<int> A, vector<int> B, int a, int b) {
  //I am so stupid, my binary search was wrong qwq

  int m = (int) B.size();

  const ll val = ask(vector<int>(m));

  vector<vector<pair<int, int>>> g(n);
  for (int i = 0; i < m; ++i) {
    g[A[i]].push_back({B[i], i});
    g[B[i]].push_back({A[i], i});
  }

  int low = 0, high = m;
  while (low + 1 < high) {
    int mid = (low + high) >> 1;
    vector<int> now(m, 1);
    fill(now.begin(), now.begin() + mid, 0);
    if (ask(now) == val) {
      high = mid;
    } else {
      low = mid;
    }
  }

  int e = low;
  int u = A[e], v = B[e];

  vector<int> S, T, root(n), dep(n, -1), par(n, -1);
  queue<int> q;
  q.push(root[u] = u), q.push(root[v] = v);
  par[u] = par[v] = e;
  dep[u] = dep[v] = 0;
  S.push_back(u), T.push_back(v);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (auto [to, i]: g[x]) {
      if (dep[to] == -1) {
        dep[to] = dep[x] + 1;
        root[to] = root[x];
        par[to] = i;
        q.push(to);
        if (root[to] == u) {
          S.push_back(to);
        } else {
          T.push_back(to);
        }
      }
    }
  }

  auto solve = [&](const vector<int> &t1, const vector<int> &t2) {
    int l = 0, r = (int) t1.size();
    while (l + 1 < r) {
      int mid = (l + r) >> 1;
      vector<int> now(m, 1);
      for (int x : t2) {
        now[par[x]] = 0;
      }
      for (int i = 0; i < mid; ++i) {
        now[par[t1[i]]] = 0;
      }
      if (ask(now) == val) {
        r = mid;
      } else {
        l = mid;
      }
    }
    return t1[l];
  };

  answer(solve(S, T), solve(T, S));
}			
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 208 KB Output is correct
8 Correct 1 ms 208 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 11 ms 1244 KB Output is correct
3 Correct 166 ms 9180 KB Output is correct
4 Correct 178 ms 9116 KB Output is correct
5 Correct 150 ms 9156 KB Output is correct
6 Correct 129 ms 9180 KB Output is correct
7 Correct 110 ms 9120 KB Output is correct
8 Correct 177 ms 9132 KB Output is correct
9 Correct 172 ms 9184 KB Output is correct
10 Correct 122 ms 9128 KB Output is correct
11 Correct 136 ms 8728 KB Output is correct
12 Correct 133 ms 8596 KB Output is correct
13 Correct 173 ms 8576 KB Output is correct
14 Correct 143 ms 8568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1232 KB Output is correct
2 Correct 21 ms 2160 KB Output is correct
3 Correct 40 ms 3132 KB Output is correct
4 Correct 135 ms 8760 KB Output is correct
5 Correct 91 ms 8756 KB Output is correct
6 Correct 89 ms 8584 KB Output is correct
7 Correct 110 ms 8576 KB Output is correct
8 Correct 94 ms 8624 KB Output is correct
9 Correct 102 ms 8612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 15 ms 1232 KB Output is correct
3 Correct 127 ms 7208 KB Output is correct
4 Correct 121 ms 9120 KB Output is correct
5 Correct 188 ms 9160 KB Output is correct
6 Correct 114 ms 9124 KB Output is correct
7 Correct 117 ms 9116 KB Output is correct
8 Correct 117 ms 9116 KB Output is correct
9 Correct 161 ms 9236 KB Output is correct
10 Correct 120 ms 9116 KB Output is correct
11 Correct 128 ms 8576 KB Output is correct
12 Correct 139 ms 8620 KB Output is correct
13 Correct 144 ms 8612 KB Output is correct
14 Correct 187 ms 8620 KB Output is correct
15 Correct 158 ms 9224 KB Output is correct
16 Correct 142 ms 9120 KB Output is correct
17 Correct 138 ms 8576 KB Output is correct
18 Correct 127 ms 8688 KB Output is correct
19 Correct 142 ms 9188 KB Output is correct
20 Correct 166 ms 8560 KB Output is correct
21 Correct 106 ms 9668 KB Output is correct
22 Correct 91 ms 9676 KB Output is correct
23 Correct 153 ms 9576 KB Output is correct
24 Correct 137 ms 9580 KB Output is correct
25 Correct 146 ms 8756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 1308 KB Output is correct
2 Correct 16 ms 1408 KB Output is correct
3 Correct 172 ms 9760 KB Output is correct
4 Correct 130 ms 9840 KB Output is correct
5 Correct 249 ms 11056 KB Output is correct
6 Correct 204 ms 10832 KB Output is correct
7 Correct 189 ms 10860 KB Output is correct
8 Correct 209 ms 10912 KB Output is correct
9 Correct 187 ms 7136 KB Output is correct
10 Correct 145 ms 7568 KB Output is correct
11 Correct 158 ms 8420 KB Output is correct
12 Correct 282 ms 10080 KB Output is correct
13 Correct 212 ms 10376 KB Output is correct
14 Correct 169 ms 10972 KB Output is correct
15 Correct 223 ms 10848 KB Output is correct
16 Correct 171 ms 8432 KB Output is correct
17 Correct 150 ms 9552 KB Output is correct
18 Correct 116 ms 9740 KB Output is correct
19 Correct 138 ms 9648 KB Output is correct
20 Correct 132 ms 9736 KB Output is correct
21 Correct 253 ms 10980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 1280 KB Output is correct
2 Correct 16 ms 1300 KB Output is correct
3 Correct 170 ms 9484 KB Output is correct
4 Correct 206 ms 9860 KB Output is correct
5 Correct 178 ms 9912 KB Output is correct
6 Correct 192 ms 10956 KB Output is correct
7 Correct 192 ms 9512 KB Output is correct
8 Correct 225 ms 9988 KB Output is correct
9 Correct 163 ms 9832 KB Output is correct
10 Correct 258 ms 10876 KB Output is correct
11 Correct 202 ms 11064 KB Output is correct
12 Correct 258 ms 10876 KB Output is correct
13 Correct 157 ms 8376 KB Output is correct
14 Correct 141 ms 7516 KB Output is correct
15 Correct 157 ms 8392 KB Output is correct
16 Correct 197 ms 7536 KB Output is correct
17 Correct 179 ms 8392 KB Output is correct
18 Correct 135 ms 7540 KB Output is correct
19 Correct 204 ms 10128 KB Output is correct
20 Correct 186 ms 10444 KB Output is correct
21 Correct 221 ms 10928 KB Output is correct
22 Correct 221 ms 11072 KB Output is correct
23 Correct 244 ms 11068 KB Output is correct
24 Correct 190 ms 10848 KB Output is correct
25 Correct 201 ms 11096 KB Output is correct
26 Correct 230 ms 11256 KB Output is correct
27 Correct 108 ms 9676 KB Output is correct
28 Correct 134 ms 9696 KB Output is correct
29 Correct 163 ms 9912 KB Output is correct
30 Correct 175 ms 9684 KB Output is correct
31 Correct 130 ms 9632 KB Output is correct
32 Correct 142 ms 9672 KB Output is correct
33 Correct 178 ms 9796 KB Output is correct
34 Correct 135 ms 9716 KB Output is correct
35 Correct 97 ms 9636 KB Output is correct
36 Correct 123 ms 9624 KB Output is correct
37 Correct 154 ms 9740 KB Output is correct
38 Correct 162 ms 9680 KB Output is correct
39 Correct 183 ms 10908 KB Output is correct
40 Correct 208 ms 10996 KB Output is correct
41 Correct 234 ms 10872 KB Output is correct
42 Correct 238 ms 11136 KB Output is correct