#include "highway.h"
//#include "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 25;
mt19937 rng (chrono::steady_clock::now().time_since_epoch().count());
int random (int l, int r) {
return uniform_int_distribution <int> (l, r) (rng);
}
vector <pair <int, int>> adj[MAXN];
vector <int> ett, ett2;
int in[MAXN], out[MAXN], dep[MAXN], tt;
void dfs (int pos, int par) {
in[pos] = ++tt;
for (auto j : adj[pos]) {
if (j.first == par) continue;
ett.push_back(j.second);
dep[j.first] = 1 + dep[pos];
dfs(j.first, pos);
}
out[pos] = tt;
}
void dfs2 (int pos) {
for (auto j : adj[pos]) {
if (in[j.first] < in[pos]) continue;
ett2.push_back(j.second);
dfs2(j.first);
}
}
void find_pair (int n, vector <int> u, vector <int> v, int a, int b) {
for (int i = 0; i + 1 < n; i++) {
adj[u[i]].push_back({v[i], i});
adj[v[i]].push_back({u[i], i});
}
vector <int> g(n - 1);
ll U = ask(g);
dfs(0, -1);
for (int i = 0; i < n - 1; i++) {
if (dep[u[i]] > dep[v[i]]) swap(u[i], v[i]);
}
int l = 0, r = n - 2, p1 = -1;
while (l <= r) {
int mid = (l + r) / 2;
g.clear(); g.resize(n - 1);
for (auto &i : g) i = 0;
for (int j = 0; j <= mid; j++) g[ett[j]] = 1;
ll V = ask(g);
if (V != U) {
r = mid - 1; p1 = mid;
} else {
l = mid + 1;
}
}
l = 0, r = n - 2; int p2 = -1;
while (l <= r) {
int mid = (l + r) / 2;
g.clear(); g.resize(n - 1);
for (auto &i : g) i = 0;
for (int j = mid; j + 1 < n; j++) g[ett[j]] = 1;
ll V = ask(g);
if (V != U) {
l = mid + 1; p2 = mid;
} else {
r = mid - 1;
}
}
p1 = ett[p1]; p2 = ett[p2];
if (in[v[p1]] <= in[v[p2]] && out[v[p2]] <= out[v[p1]]) {
answer(u[p1], v[p2]);
return;
}
dfs2(v[p1]);
l = 0, r = (int)ett2.size() - 1; int ans = -1;
while (l <= r) {
int mid = (l + r) / 2;
g.clear(); g.resize(n - 1);
for (auto &i : g) i = 0;
for (int i = mid; i < (int)ett2.size(); i++) {
g[ett2[i]] = 1;
}
ll V = ask(g);
if (V != U) {
l = mid + 1; ans = mid;
} else {
r = mid - 1;
}
}
answer(v[ett2[ans]], v[p2]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
3804 KB |
Output is correct |
2 |
Correct |
1 ms |
3796 KB |
Output is correct |
3 |
Correct |
1 ms |
3928 KB |
Output is correct |
4 |
Correct |
1 ms |
3804 KB |
Output is correct |
5 |
Correct |
2 ms |
3796 KB |
Output is correct |
6 |
Correct |
2 ms |
3928 KB |
Output is correct |
7 |
Correct |
2 ms |
3928 KB |
Output is correct |
8 |
Correct |
1 ms |
3800 KB |
Output is correct |
9 |
Correct |
1 ms |
3804 KB |
Output is correct |
10 |
Correct |
2 ms |
3928 KB |
Output is correct |
11 |
Correct |
1 ms |
3796 KB |
Output is correct |
12 |
Correct |
1 ms |
3960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3852 KB |
Output is correct |
2 |
Correct |
12 ms |
4580 KB |
Output is correct |
3 |
Correct |
116 ms |
10236 KB |
Output is correct |
4 |
Correct |
91 ms |
10272 KB |
Output is correct |
5 |
Correct |
94 ms |
9816 KB |
Output is correct |
6 |
Correct |
84 ms |
10060 KB |
Output is correct |
7 |
Correct |
114 ms |
10296 KB |
Output is correct |
8 |
Correct |
107 ms |
9612 KB |
Output is correct |
9 |
Correct |
97 ms |
10304 KB |
Output is correct |
10 |
Correct |
95 ms |
9784 KB |
Output is correct |
11 |
Correct |
91 ms |
11680 KB |
Output is correct |
12 |
Correct |
80 ms |
11932 KB |
Output is correct |
13 |
Correct |
86 ms |
11360 KB |
Output is correct |
14 |
Correct |
83 ms |
10680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
5236 KB |
Output is correct |
2 |
Correct |
16 ms |
6668 KB |
Output is correct |
3 |
Correct |
22 ms |
8044 KB |
Output is correct |
4 |
Correct |
76 ms |
16732 KB |
Output is correct |
5 |
Correct |
94 ms |
16284 KB |
Output is correct |
6 |
Correct |
99 ms |
17052 KB |
Output is correct |
7 |
Correct |
88 ms |
16312 KB |
Output is correct |
8 |
Correct |
80 ms |
16564 KB |
Output is correct |
9 |
Correct |
86 ms |
16304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3844 KB |
Output is correct |
2 |
Correct |
11 ms |
4552 KB |
Output is correct |
3 |
Correct |
74 ms |
8484 KB |
Output is correct |
4 |
Correct |
132 ms |
10008 KB |
Output is correct |
5 |
Correct |
90 ms |
10296 KB |
Output is correct |
6 |
Correct |
99 ms |
10520 KB |
Output is correct |
7 |
Correct |
126 ms |
10452 KB |
Output is correct |
8 |
Correct |
86 ms |
10040 KB |
Output is correct |
9 |
Correct |
98 ms |
10060 KB |
Output is correct |
10 |
Correct |
104 ms |
9812 KB |
Output is correct |
11 |
Correct |
133 ms |
10976 KB |
Output is correct |
12 |
Correct |
108 ms |
12056 KB |
Output is correct |
13 |
Correct |
101 ms |
11916 KB |
Output is correct |
14 |
Correct |
103 ms |
11756 KB |
Output is correct |
15 |
Correct |
105 ms |
9964 KB |
Output is correct |
16 |
Correct |
88 ms |
10048 KB |
Output is correct |
17 |
Correct |
104 ms |
11528 KB |
Output is correct |
18 |
Correct |
117 ms |
11164 KB |
Output is correct |
19 |
Correct |
94 ms |
10044 KB |
Output is correct |
20 |
Correct |
130 ms |
12776 KB |
Output is correct |
21 |
Runtime error |
75 ms |
20584 KB |
Execution killed with signal 11 |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
4184 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
4184 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |