#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
#define ad push_back
#define MP make_pair
#define lli long long
#define fr first
#define sc second
const int N = 1e6 + 30;
int n, m;
vector<pair<int, int> > g[N], fp;
vector<int> w;
int xr[N], col[N];
pair<int, int> pr[N];
lli sum;
void dfs(int v, int par)
{
for(auto p : g[v])
{
if(p.fr == par) continue;
xr[p.fr] = xr[v] + 1;
pr[p.fr] = MP(v, p.sc);
dfs(p.fr, v);
}
}
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B)
{
n = N, m = U.size();
for (int i = 0; i < m; i++)
{
w.ad(0);
g[U[i]].ad(MP(V[i], i));
g[V[i]].ad(MP(U[i], i));
}
sum = ask(w);
dfs(0, 0);
for (int i = 1; i < n; i++)
{
fp.ad(MP(xr[i], pr[i].sc));
//cout << pr[i].sc << " ";
}
sort(fp.begin(), fp.end());
reverse(fp.begin(), fp.end());
int l = 0, r = m - 1, ans = 0;
while(l <= r)
{
int mid = (l + r) / 2;
for (int i = 0; i < m; i++) w[i] = 0;
for (int i = 0; i <= mid; i++) w[fp[i].sc] = 1;
if(ask(w) == sum) l = mid + 1;
else ans = mid, r = mid - 1;
}
if(xr[U[fp[ans].sc]] > xr[V[fp[ans].sc]]) ans = U[fp[ans].sc];
else ans = V[fp[ans].sc];
int S = ans;
//cout << S << endl;
for (int i = 0; i < m; i++) w[i] = 0;
int v = ans;
while(v)
{
w[pr[v].sc] = 1;
v = pr[v].fr;
}
lli sm = ask(w);
int s = (sm - sum) / (B - A);
v = ans;
for (int i = 0; i < s; i++)
{
col[pr[v].sc] = 1;
v=pr[v].fr;
}
l = 0, r = m - 1, ans = -1;
while(l <= r)
{
int mid = (l + r) / 2;
for (int i = 0; i < m; i++) w[i] = col[i];
for (int i = 0; i <= mid; i++) w[fp[i].sc] = 1;
if(ask(w) == sm) l = mid + 1;
else ans = mid, r = mid - 1;
}
if(ans == -1) ans = v;
else if(xr[U[fp[ans].sc]] > xr[V[fp[ans].sc]]) ans = U[fp[ans].sc];
else ans = V[fp[ans].sc];
int T = ans;
answer(S, T);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
23768 KB |
Output is correct |
2 |
Correct |
17 ms |
23792 KB |
Output is correct |
3 |
Correct |
16 ms |
23792 KB |
Output is correct |
4 |
Correct |
18 ms |
23796 KB |
Output is correct |
5 |
Correct |
19 ms |
23800 KB |
Output is correct |
6 |
Correct |
17 ms |
23720 KB |
Output is correct |
7 |
Correct |
18 ms |
23788 KB |
Output is correct |
8 |
Correct |
17 ms |
23752 KB |
Output is correct |
9 |
Correct |
18 ms |
23724 KB |
Output is correct |
10 |
Correct |
18 ms |
23880 KB |
Output is correct |
11 |
Correct |
16 ms |
23796 KB |
Output is correct |
12 |
Correct |
17 ms |
23784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
23776 KB |
Output is correct |
2 |
Correct |
31 ms |
24616 KB |
Output is correct |
3 |
Correct |
175 ms |
31084 KB |
Output is correct |
4 |
Correct |
182 ms |
31088 KB |
Output is correct |
5 |
Correct |
178 ms |
31132 KB |
Output is correct |
6 |
Correct |
225 ms |
31080 KB |
Output is correct |
7 |
Correct |
180 ms |
31116 KB |
Output is correct |
8 |
Correct |
167 ms |
31120 KB |
Output is correct |
9 |
Correct |
165 ms |
31076 KB |
Output is correct |
10 |
Correct |
182 ms |
31128 KB |
Output is correct |
11 |
Correct |
195 ms |
32344 KB |
Output is correct |
12 |
Correct |
201 ms |
33076 KB |
Output is correct |
13 |
Correct |
185 ms |
32500 KB |
Output is correct |
14 |
Correct |
191 ms |
31816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
25392 KB |
Output is correct |
2 |
Correct |
44 ms |
26948 KB |
Output is correct |
3 |
Correct |
59 ms |
28372 KB |
Output is correct |
4 |
Correct |
132 ms |
37524 KB |
Output is correct |
5 |
Correct |
124 ms |
37528 KB |
Output is correct |
6 |
Correct |
136 ms |
37620 KB |
Output is correct |
7 |
Correct |
136 ms |
37632 KB |
Output is correct |
8 |
Correct |
150 ms |
37524 KB |
Output is correct |
9 |
Correct |
145 ms |
37624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
23796 KB |
Output is correct |
2 |
Correct |
31 ms |
24624 KB |
Output is correct |
3 |
Correct |
132 ms |
29772 KB |
Output is correct |
4 |
Correct |
193 ms |
31128 KB |
Output is correct |
5 |
Correct |
166 ms |
31136 KB |
Output is correct |
6 |
Correct |
216 ms |
31124 KB |
Output is correct |
7 |
Correct |
198 ms |
31128 KB |
Output is correct |
8 |
Correct |
192 ms |
31128 KB |
Output is correct |
9 |
Correct |
171 ms |
31128 KB |
Output is correct |
10 |
Correct |
191 ms |
31100 KB |
Output is correct |
11 |
Correct |
188 ms |
31776 KB |
Output is correct |
12 |
Correct |
176 ms |
33172 KB |
Output is correct |
13 |
Correct |
182 ms |
32624 KB |
Output is correct |
14 |
Correct |
188 ms |
33216 KB |
Output is correct |
15 |
Correct |
173 ms |
31112 KB |
Output is correct |
16 |
Correct |
169 ms |
31212 KB |
Output is correct |
17 |
Correct |
190 ms |
32792 KB |
Output is correct |
18 |
Correct |
194 ms |
32316 KB |
Output is correct |
19 |
Correct |
177 ms |
31120 KB |
Output is correct |
20 |
Correct |
179 ms |
33696 KB |
Output is correct |
21 |
Correct |
149 ms |
31560 KB |
Output is correct |
22 |
Correct |
149 ms |
31616 KB |
Output is correct |
23 |
Correct |
160 ms |
31424 KB |
Output is correct |
24 |
Correct |
163 ms |
32044 KB |
Output is correct |
25 |
Correct |
182 ms |
36588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
272 ms |
262148 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
225 ms |
262148 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |