#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
template <class F> int binary_search(int ok, int ng, int md, const F& f) {
while (abs(ok - ng) > 1) {
(f(md) ? ok : ng) = md;
md = (ok + ng) / 2;
}
return ok;
}
void find_pair(int N, vector<int> U, vector<int> V, int A, int B) {
const int M = (int)U.size();
vector<vector<int>> G(N);
for (int i = 0; i < M; ++i) {
G[U[i]].push_back(i);
G[V[i]].push_back(i);
}
vector<char> dead(N);
const auto bfs_order = [&](int src) {
vector<int> ret;
vector<char> done(N);
queue<int> que;
ret.reserve(N);
const auto push = [&](int u) {
if (!dead[u] && !done[u]) {
done[u] = true;
ret.push_back(u);
que.push(u);
}
};
push(src);
while (!que.empty()) {
const int u = que.front();
que.pop();
for (const int e : G[u]) {
push(u ^ U[e] ^ V[e]);
}
}
return ret;
};
const long long best = ask(vector(M, 0));
const int P = binary_search(0, N, N / 3, [&](int thres) {
vector<int> w(M);
for (int i = 0; i < thres; ++i) {
for (const int e : G[i]) w[e] = 1;
}
return ask(w) == best;
});
for (int i = 0; i < P; ++i) dead[i] = true;
const int S = [&] {
const auto ord = bfs_order(P);
const int n = (int)ord.size();
const int k = binary_search(n, 0, 2 * n / 3, [&](int thres) {
vector<int> w(M);
for (int i = thres; i < n; ++i) {
for (const int e : G[ord[i]]) w[e] = 1;
}
for (int i = 0; i < N; ++i) {
if (dead[i]) {
for (const int e : G[i]) w[e] = 1;
}
}
return ask(w) == best;
});
for (int i = k; i < n; ++i) dead[ord[i]] = true;
return ord[k - 1];
}();
const int T = [&] {
const auto ord = bfs_order(S);
const int n = (int)ord.size();
const int k = binary_search(n, 0, 2 * n / 3, [&](int thres) {
vector<int> w(M);
for (int i = thres; i < n; ++i) {
for (const int e : G[ord[i]]) w[e] = 1;
}
for (int i = 0; i < N; ++i) {
if (dead[i]) {
for (const int e : G[i]) w[e] = 1;
}
}
return ask(w) == best;
});
for (int i = k; i < n; ++i) dead[ord[i]] = true;
return ord[k - 1];
}();
answer(S, T);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
0 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 |
0 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
208 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 |
368 KB |
Output is correct |
2 |
Correct |
13 ms |
1076 KB |
Output is correct |
3 |
Correct |
128 ms |
7660 KB |
Output is correct |
4 |
Correct |
109 ms |
7664 KB |
Output is correct |
5 |
Correct |
138 ms |
7764 KB |
Output is correct |
6 |
Correct |
105 ms |
7664 KB |
Output is correct |
7 |
Correct |
107 ms |
7672 KB |
Output is correct |
8 |
Correct |
141 ms |
7680 KB |
Output is correct |
9 |
Correct |
102 ms |
7668 KB |
Output is correct |
10 |
Correct |
112 ms |
7680 KB |
Output is correct |
11 |
Correct |
146 ms |
7524 KB |
Output is correct |
12 |
Correct |
134 ms |
7540 KB |
Output is correct |
13 |
Correct |
129 ms |
7512 KB |
Output is correct |
14 |
Correct |
105 ms |
7540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
1140 KB |
Output is correct |
2 |
Correct |
21 ms |
1952 KB |
Output is correct |
3 |
Correct |
34 ms |
2688 KB |
Output is correct |
4 |
Correct |
108 ms |
7432 KB |
Output is correct |
5 |
Correct |
114 ms |
7460 KB |
Output is correct |
6 |
Correct |
112 ms |
7460 KB |
Output is correct |
7 |
Correct |
65 ms |
7428 KB |
Output is correct |
8 |
Correct |
87 ms |
7436 KB |
Output is correct |
9 |
Correct |
76 ms |
7444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
12 ms |
1160 KB |
Output is correct |
3 |
Correct |
74 ms |
5964 KB |
Output is correct |
4 |
Correct |
115 ms |
7552 KB |
Output is correct |
5 |
Correct |
132 ms |
7560 KB |
Output is correct |
6 |
Correct |
98 ms |
7528 KB |
Output is correct |
7 |
Correct |
106 ms |
7564 KB |
Output is correct |
8 |
Correct |
99 ms |
7540 KB |
Output is correct |
9 |
Correct |
153 ms |
7584 KB |
Output is correct |
10 |
Correct |
138 ms |
7728 KB |
Output is correct |
11 |
Correct |
81 ms |
7436 KB |
Output is correct |
12 |
Correct |
127 ms |
7468 KB |
Output is correct |
13 |
Correct |
129 ms |
7440 KB |
Output is correct |
14 |
Correct |
109 ms |
7440 KB |
Output is correct |
15 |
Correct |
124 ms |
7780 KB |
Output is correct |
16 |
Correct |
123 ms |
7556 KB |
Output is correct |
17 |
Correct |
116 ms |
7448 KB |
Output is correct |
18 |
Correct |
79 ms |
7436 KB |
Output is correct |
19 |
Correct |
118 ms |
7540 KB |
Output is correct |
20 |
Correct |
93 ms |
7440 KB |
Output is correct |
21 |
Correct |
117 ms |
7824 KB |
Output is correct |
22 |
Correct |
137 ms |
7812 KB |
Output is correct |
23 |
Correct |
77 ms |
8060 KB |
Output is correct |
24 |
Correct |
91 ms |
8016 KB |
Output is correct |
25 |
Correct |
146 ms |
7664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
1104 KB |
Output is correct |
2 |
Correct |
16 ms |
1104 KB |
Output is correct |
3 |
Correct |
120 ms |
8004 KB |
Output is correct |
4 |
Correct |
203 ms |
8160 KB |
Output is correct |
5 |
Correct |
172 ms |
8760 KB |
Output is correct |
6 |
Correct |
190 ms |
8668 KB |
Output is correct |
7 |
Correct |
175 ms |
8676 KB |
Output is correct |
8 |
Correct |
206 ms |
8704 KB |
Output is correct |
9 |
Correct |
162 ms |
5488 KB |
Output is correct |
10 |
Correct |
112 ms |
5824 KB |
Output is correct |
11 |
Correct |
127 ms |
6028 KB |
Output is correct |
12 |
Correct |
180 ms |
7844 KB |
Output is correct |
13 |
Correct |
194 ms |
8232 KB |
Output is correct |
14 |
Correct |
138 ms |
8492 KB |
Output is correct |
15 |
Correct |
174 ms |
8528 KB |
Output is correct |
16 |
Correct |
133 ms |
6396 KB |
Output is correct |
17 |
Correct |
124 ms |
7960 KB |
Output is correct |
18 |
Correct |
123 ms |
7960 KB |
Output is correct |
19 |
Correct |
87 ms |
7984 KB |
Output is correct |
20 |
Correct |
90 ms |
8000 KB |
Output is correct |
21 |
Correct |
186 ms |
8552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
1076 KB |
Output is correct |
2 |
Correct |
15 ms |
1188 KB |
Output is correct |
3 |
Correct |
137 ms |
7904 KB |
Output is correct |
4 |
Correct |
164 ms |
8012 KB |
Output is correct |
5 |
Correct |
190 ms |
8132 KB |
Output is correct |
6 |
Correct |
172 ms |
8688 KB |
Output is correct |
7 |
Correct |
121 ms |
7880 KB |
Output is correct |
8 |
Correct |
121 ms |
8048 KB |
Output is correct |
9 |
Correct |
131 ms |
8252 KB |
Output is correct |
10 |
Correct |
186 ms |
8684 KB |
Output is correct |
11 |
Correct |
190 ms |
8680 KB |
Output is correct |
12 |
Correct |
166 ms |
8852 KB |
Output is correct |
13 |
Correct |
114 ms |
6024 KB |
Output is correct |
14 |
Correct |
103 ms |
5652 KB |
Output is correct |
15 |
Correct |
100 ms |
6012 KB |
Output is correct |
16 |
Correct |
130 ms |
5668 KB |
Output is correct |
17 |
Correct |
100 ms |
6060 KB |
Output is correct |
18 |
Correct |
142 ms |
5648 KB |
Output is correct |
19 |
Correct |
128 ms |
7792 KB |
Output is correct |
20 |
Correct |
136 ms |
8112 KB |
Output is correct |
21 |
Correct |
134 ms |
8528 KB |
Output is correct |
22 |
Correct |
175 ms |
8452 KB |
Output is correct |
23 |
Correct |
150 ms |
8536 KB |
Output is correct |
24 |
Correct |
129 ms |
8508 KB |
Output is correct |
25 |
Correct |
134 ms |
8484 KB |
Output is correct |
26 |
Correct |
158 ms |
8552 KB |
Output is correct |
27 |
Correct |
117 ms |
7968 KB |
Output is correct |
28 |
Correct |
88 ms |
7908 KB |
Output is correct |
29 |
Correct |
111 ms |
8052 KB |
Output is correct |
30 |
Correct |
104 ms |
7956 KB |
Output is correct |
31 |
Correct |
121 ms |
7948 KB |
Output is correct |
32 |
Correct |
117 ms |
7864 KB |
Output is correct |
33 |
Correct |
98 ms |
8052 KB |
Output is correct |
34 |
Correct |
137 ms |
8008 KB |
Output is correct |
35 |
Correct |
96 ms |
8028 KB |
Output is correct |
36 |
Correct |
128 ms |
7860 KB |
Output is correct |
37 |
Correct |
103 ms |
8024 KB |
Output is correct |
38 |
Correct |
97 ms |
7992 KB |
Output is correct |
39 |
Correct |
157 ms |
8532 KB |
Output is correct |
40 |
Correct |
148 ms |
8524 KB |
Output is correct |
41 |
Correct |
144 ms |
8908 KB |
Output is correct |
42 |
Correct |
163 ms |
8936 KB |
Output is correct |