Submission #606645

# Submission time Handle Problem Language Result Execution time Memory
606645 2022-07-26T07:34:43 Z piOOE Highway Tolls (IOI18_highway) C++17
100 / 100
300 ms 11252 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, by 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 296 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 208 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 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 0 ms 208 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 10 ms 1304 KB Output is correct
3 Correct 163 ms 9204 KB Output is correct
4 Correct 180 ms 9244 KB Output is correct
5 Correct 111 ms 9232 KB Output is correct
6 Correct 134 ms 9116 KB Output is correct
7 Correct 100 ms 9108 KB Output is correct
8 Correct 158 ms 9136 KB Output is correct
9 Correct 122 ms 9192 KB Output is correct
10 Correct 121 ms 9120 KB Output is correct
11 Correct 181 ms 8712 KB Output is correct
12 Correct 134 ms 8696 KB Output is correct
13 Correct 210 ms 8768 KB Output is correct
14 Correct 129 ms 8568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 1232 KB Output is correct
2 Correct 49 ms 2164 KB Output is correct
3 Correct 29 ms 3144 KB Output is correct
4 Correct 109 ms 8756 KB Output is correct
5 Correct 90 ms 8760 KB Output is correct
6 Correct 101 ms 8588 KB Output is correct
7 Correct 86 ms 8628 KB Output is correct
8 Correct 89 ms 8628 KB Output is correct
9 Correct 105 ms 8572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 316 KB Output is correct
2 Correct 13 ms 1292 KB Output is correct
3 Correct 100 ms 7200 KB Output is correct
4 Correct 122 ms 9200 KB Output is correct
5 Correct 112 ms 9128 KB Output is correct
6 Correct 127 ms 9120 KB Output is correct
7 Correct 133 ms 9184 KB Output is correct
8 Correct 125 ms 9156 KB Output is correct
9 Correct 152 ms 9264 KB Output is correct
10 Correct 122 ms 9124 KB Output is correct
11 Correct 152 ms 8652 KB Output is correct
12 Correct 139 ms 8660 KB Output is correct
13 Correct 202 ms 8624 KB Output is correct
14 Correct 130 ms 8656 KB Output is correct
15 Correct 109 ms 9124 KB Output is correct
16 Correct 145 ms 9124 KB Output is correct
17 Correct 181 ms 8580 KB Output is correct
18 Correct 171 ms 8688 KB Output is correct
19 Correct 107 ms 9120 KB Output is correct
20 Correct 125 ms 8556 KB Output is correct
21 Correct 101 ms 9712 KB Output is correct
22 Correct 95 ms 9648 KB Output is correct
23 Correct 144 ms 9508 KB Output is correct
24 Correct 150 ms 9472 KB Output is correct
25 Correct 141 ms 8680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 1272 KB Output is correct
2 Correct 15 ms 1392 KB Output is correct
3 Correct 197 ms 9644 KB Output is correct
4 Correct 132 ms 9844 KB Output is correct
5 Correct 183 ms 11056 KB Output is correct
6 Correct 213 ms 10836 KB Output is correct
7 Correct 227 ms 10912 KB Output is correct
8 Correct 205 ms 10904 KB Output is correct
9 Correct 164 ms 7124 KB Output is correct
10 Correct 95 ms 7564 KB Output is correct
11 Correct 130 ms 8400 KB Output is correct
12 Correct 184 ms 10184 KB Output is correct
13 Correct 186 ms 10392 KB Output is correct
14 Correct 185 ms 10968 KB Output is correct
15 Correct 211 ms 10892 KB Output is correct
16 Correct 194 ms 8432 KB Output is correct
17 Correct 124 ms 9608 KB Output is correct
18 Correct 115 ms 9744 KB Output is correct
19 Correct 124 ms 9652 KB Output is correct
20 Correct 165 ms 9844 KB Output is correct
21 Correct 163 ms 11008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 1232 KB Output is correct
2 Correct 19 ms 1352 KB Output is correct
3 Correct 130 ms 9468 KB Output is correct
4 Correct 154 ms 9872 KB Output is correct
5 Correct 198 ms 10012 KB Output is correct
6 Correct 222 ms 10896 KB Output is correct
7 Correct 145 ms 9600 KB Output is correct
8 Correct 176 ms 9996 KB Output is correct
9 Correct 137 ms 9840 KB Output is correct
10 Correct 226 ms 10848 KB Output is correct
11 Correct 224 ms 11072 KB Output is correct
12 Correct 233 ms 10884 KB Output is correct
13 Correct 130 ms 8400 KB Output is correct
14 Correct 106 ms 7524 KB Output is correct
15 Correct 215 ms 8400 KB Output is correct
16 Correct 200 ms 7508 KB Output is correct
17 Correct 119 ms 8392 KB Output is correct
18 Correct 173 ms 7512 KB Output is correct
19 Correct 253 ms 10092 KB Output is correct
20 Correct 164 ms 10452 KB Output is correct
21 Correct 212 ms 11068 KB Output is correct
22 Correct 267 ms 11068 KB Output is correct
23 Correct 277 ms 11172 KB Output is correct
24 Correct 278 ms 10928 KB Output is correct
25 Correct 300 ms 11068 KB Output is correct
26 Correct 260 ms 11252 KB Output is correct
27 Correct 164 ms 9672 KB Output is correct
28 Correct 132 ms 9624 KB Output is correct
29 Correct 168 ms 9812 KB Output is correct
30 Correct 121 ms 9784 KB Output is correct
31 Correct 129 ms 9624 KB Output is correct
32 Correct 147 ms 9696 KB Output is correct
33 Correct 181 ms 9852 KB Output is correct
34 Correct 104 ms 9660 KB Output is correct
35 Correct 167 ms 9628 KB Output is correct
36 Correct 126 ms 9524 KB Output is correct
37 Correct 125 ms 9820 KB Output is correct
38 Correct 153 ms 9776 KB Output is correct
39 Correct 213 ms 11024 KB Output is correct
40 Correct 209 ms 11000 KB Output is correct
41 Correct 289 ms 10916 KB Output is correct
42 Correct 285 ms 11128 KB Output is correct