Submission #1057301

# Submission time Handle Problem Language Result Execution time Memory
1057301 2024-08-13T16:44:42 Z TAhmed33 Highway Tolls (IOI18_highway) C++17
100 / 100
195 ms 43844 KB
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
//#include "grader.cpp"
typedef long long ll;
const int MAXN = 2e5 + 25;
vector <int> adj[MAXN];
int n, m;
map <int, int> ind[MAXN];
vector <int> cc[MAXN];
int dist[MAXN]; 
int in[MAXN], out[MAXN], tt, p[MAXN];
int gg[MAXN];
void dfs (int pos) {
  in[pos] = ++tt; gg[tt] = pos;
  for (auto j : cc[pos]) {
    p[j] = pos;
    dfs(j);
  }
  out[pos] = tt;
}
void find_pair (int N, vector <int> U, vector <int> V, int A, int B) {
  n = N; m = U.size();
  vector <int> x(m, 0);
  ll z = ask(x);
  for (int i = 0; i < m; i++) {
    adj[U[i]].push_back(V[i]);
    adj[V[i]].push_back(U[i]);
    ind[U[i]][V[i]] = ind[V[i]][U[i]] = i;
  }
  int l = 0, r = m - 1, ans = -1;
  while (l <= r) {
    int mid = (l + r) / 2;
    x.assign(m, 0);
    for (int j = 0; j < mid; j++) {
      x[j] = 1;
    }
    if (ask(x) == z) {
      l = mid + 1; ans = mid;
    } else {
      r = mid - 1;
    }
  }
  memset(dist, -1, sizeof(dist));
  queue <int> cur;
  cur.push(U[ans]); cur.push(V[ans]); dist[V[ans]] = 1; dist[U[ans]] = 0;
  cc[U[ans]].push_back(V[ans]);
  vector <int> spec = {ans};
  while (!cur.empty()) {
    auto k = cur.front();
    cur.pop();
    for (auto j : adj[k]) {
      if (dist[j] == -1) {
        dist[j] = dist[k] + 1;
        cc[k].push_back(j);
        cur.push(j); 
        spec.push_back(ind[j][k]);
      }
    }
  }
  x.assign(m, 1);
  p[U[ans]] = -1;
  swap(cc[U[ans]].front(), cc[U[ans]].back());
  dfs(U[ans]);
  l = 2, r = in[V[ans]] - 1; int ans2 = -1;
  while (l <= r) {
    int mid = (l + r) / 2;
    for (auto i : spec) {
      x[i] = 0;
    }
    for (int j = mid; j <= in[V[ans]] - 1; j++) {
      x[ind[gg[j]][p[gg[j]]]] = 1;
    }
    if (ask(x) != z) {
      l = mid + 1; ans2 = mid;
    } else {
      r = mid - 1;
    }
  }
  if (ans2 == -1) {
    ans2 = U[ans];
  } else {
    ans2 = gg[ans2];
  }
  l = in[V[ans]], r = n; int ans3 = -1;
  while (l <= r) {
    int mid = (l + r) / 2;
    for (auto i : spec) {
      x[i] = 0;
    }
    for (int j = mid; j <= n; j++) {
      x[ind[gg[j]][p[gg[j]]]] = 1;
    }
    if (ask(x) != z) {
      l = mid + 1; ans3 = mid;
    } else {
      r = mid - 1;
    }
  }
  assert(ans3 != -1);
  ans3 = gg[ans3];
  answer(ans2, ans3);
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 22872 KB Output is correct
2 Correct 3 ms 22872 KB Output is correct
3 Correct 3 ms 22872 KB Output is correct
4 Correct 3 ms 22872 KB Output is correct
5 Correct 3 ms 22952 KB Output is correct
6 Correct 3 ms 22872 KB Output is correct
7 Correct 3 ms 22872 KB Output is correct
8 Correct 3 ms 22872 KB Output is correct
9 Correct 3 ms 22872 KB Output is correct
10 Correct 3 ms 22944 KB Output is correct
11 Correct 3 ms 22872 KB Output is correct
12 Correct 4 ms 23084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 23128 KB Output is correct
2 Correct 13 ms 24580 KB Output is correct
3 Correct 111 ms 38076 KB Output is correct
4 Correct 131 ms 38092 KB Output is correct
5 Correct 132 ms 38092 KB Output is correct
6 Correct 116 ms 38088 KB Output is correct
7 Correct 128 ms 38080 KB Output is correct
8 Correct 127 ms 38108 KB Output is correct
9 Correct 104 ms 38072 KB Output is correct
10 Correct 125 ms 38092 KB Output is correct
11 Correct 137 ms 40160 KB Output is correct
12 Correct 122 ms 40712 KB Output is correct
13 Correct 142 ms 40376 KB Output is correct
14 Correct 134 ms 40428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 25176 KB Output is correct
2 Correct 18 ms 27436 KB Output is correct
3 Correct 25 ms 29520 KB Output is correct
4 Correct 74 ms 41944 KB Output is correct
5 Correct 76 ms 41980 KB Output is correct
6 Correct 69 ms 42952 KB Output is correct
7 Correct 76 ms 43340 KB Output is correct
8 Correct 72 ms 42320 KB Output is correct
9 Correct 93 ms 42476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 23128 KB Output is correct
2 Correct 12 ms 24440 KB Output is correct
3 Correct 70 ms 34640 KB Output is correct
4 Correct 106 ms 38084 KB Output is correct
5 Correct 135 ms 38080 KB Output is correct
6 Correct 93 ms 38540 KB Output is correct
7 Correct 123 ms 38080 KB Output is correct
8 Correct 94 ms 37932 KB Output is correct
9 Correct 112 ms 38340 KB Output is correct
10 Correct 140 ms 38080 KB Output is correct
11 Correct 108 ms 40208 KB Output is correct
12 Correct 142 ms 40724 KB Output is correct
13 Correct 128 ms 40560 KB Output is correct
14 Correct 134 ms 40760 KB Output is correct
15 Correct 116 ms 38108 KB Output is correct
16 Correct 125 ms 38096 KB Output is correct
17 Correct 136 ms 40284 KB Output is correct
18 Correct 138 ms 40568 KB Output is correct
19 Correct 121 ms 38080 KB Output is correct
20 Correct 134 ms 40912 KB Output is correct
21 Correct 98 ms 37604 KB Output is correct
22 Correct 96 ms 37504 KB Output is correct
23 Correct 115 ms 37584 KB Output is correct
24 Correct 125 ms 38056 KB Output is correct
25 Correct 114 ms 42760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 24664 KB Output is correct
2 Correct 16 ms 24920 KB Output is correct
3 Correct 133 ms 39320 KB Output is correct
4 Correct 145 ms 40512 KB Output is correct
5 Correct 181 ms 42840 KB Output is correct
6 Correct 170 ms 42836 KB Output is correct
7 Correct 187 ms 42836 KB Output is correct
8 Correct 183 ms 42836 KB Output is correct
9 Correct 144 ms 39856 KB Output is correct
10 Correct 147 ms 40768 KB Output is correct
11 Correct 145 ms 40376 KB Output is correct
12 Correct 169 ms 41984 KB Output is correct
13 Correct 177 ms 42340 KB Output is correct
14 Correct 195 ms 43144 KB Output is correct
15 Correct 191 ms 42972 KB Output is correct
16 Correct 153 ms 40968 KB Output is correct
17 Correct 130 ms 37764 KB Output is correct
18 Correct 124 ms 38308 KB Output is correct
19 Correct 119 ms 38128 KB Output is correct
20 Correct 125 ms 38096 KB Output is correct
21 Correct 168 ms 43480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 24664 KB Output is correct
2 Correct 14 ms 24740 KB Output is correct
3 Correct 144 ms 39428 KB Output is correct
4 Correct 153 ms 39908 KB Output is correct
5 Correct 160 ms 40516 KB Output is correct
6 Correct 185 ms 43012 KB Output is correct
7 Correct 136 ms 39428 KB Output is correct
8 Correct 159 ms 40144 KB Output is correct
9 Correct 141 ms 40520 KB Output is correct
10 Correct 192 ms 42892 KB Output is correct
11 Correct 180 ms 42820 KB Output is correct
12 Correct 183 ms 42844 KB Output is correct
13 Correct 134 ms 40380 KB Output is correct
14 Correct 140 ms 40748 KB Output is correct
15 Correct 135 ms 40396 KB Output is correct
16 Correct 138 ms 40764 KB Output is correct
17 Correct 138 ms 40632 KB Output is correct
18 Correct 148 ms 40756 KB Output is correct
19 Correct 193 ms 42100 KB Output is correct
20 Correct 180 ms 42416 KB Output is correct
21 Correct 164 ms 42972 KB Output is correct
22 Correct 183 ms 42952 KB Output is correct
23 Correct 177 ms 43844 KB Output is correct
24 Correct 188 ms 42988 KB Output is correct
25 Correct 193 ms 43056 KB Output is correct
26 Correct 174 ms 42976 KB Output is correct
27 Correct 136 ms 38228 KB Output is correct
28 Correct 115 ms 37860 KB Output is correct
29 Correct 120 ms 38376 KB Output is correct
30 Correct 121 ms 38216 KB Output is correct
31 Correct 138 ms 37948 KB Output is correct
32 Correct 143 ms 37848 KB Output is correct
33 Correct 111 ms 38284 KB Output is correct
34 Correct 147 ms 37892 KB Output is correct
35 Correct 117 ms 37884 KB Output is correct
36 Correct 113 ms 38012 KB Output is correct
37 Correct 134 ms 38432 KB Output is correct
38 Correct 116 ms 38820 KB Output is correct
39 Correct 179 ms 43484 KB Output is correct
40 Correct 170 ms 43820 KB Output is correct
41 Correct 186 ms 43188 KB Output is correct
42 Correct 183 ms 43232 KB Output is correct