#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
void find_pair(int n, vector<int> U, vector<int> V, int A, int B){
int m = (int) U.size();
vector<pii> g[n + 1];
for (int i = 0; i < m; i++){
U[i]++; V[i]++;
g[U[i]].pb({V[i], i});
g[V[i]].pb({U[i], i});
}
vector<int> w(m);
ll nl = ask(w);
int l = 0, r = m - 1;
while (l + 1 < r){
int k = (l + r) / 2;
fill(w.begin(), w.end(), 0);
for (int i = k + 1; i < m; i++) w[i] = 1;
if (ask(w) == nl){
r = k;
}
else {
l = k + 1;
}
}
fill(w.begin(), w.end(), 0);
for (int i = l + 1; i < m; i++) w[i] = 1;
if (ask(w) == nl){
r = l;
}
int x = r;
vector<bool> used(n + 1);
vector<int> ed = {x};
queue<int> q;
q.push(V[x]);
q.push(U[x]);
used[V[x]] = used[U[x]] = 1;
while (!q.empty()){
int f = q.front(); q.pop();
for (auto [i, j]: g[f]){
if (used[i] || j == x) continue;
used[i] = 1;
q.push(i);
ed.pb(j);
}
}
fill(w.begin(), w.end(), 1);
auto cl = [&](){
for (int i: ed) w[i] = 0;
};
cl();
vector<pii> t[n + 1];
for (int i: ed){
t[U[i]].pb({V[i], i});
t[V[i]].pb({U[i], i});
}
vector<int> d(n + 1), p(n + 1), pe(n + 1);
function<void(int, int, vector<int>&, vector<int>&)> dfs = [&](int v, int pr, vector<int>& ed, vector<int>& q){
q.pb(v);
p[v] = pr;
for (auto [i, j]: t[v]){
if (i == pr || j == x) continue;
d[i] = d[v] + 1;
pe[i] = j;
ed.pb(j);
dfs(i, v, ed, q);
}
};
vector<int> d1, d2, t1, t2;
dfs(U[x], 0, d1, t1);
dfs(V[x], 0, d2, t2);
int dist = (int) (ask(w) / A);
auto add = [&](int x, int y){
while (y != x && !w[pe[y]]){
w[pe[y]] = 1;
y = p[y];
}
};
auto solve = [&](int v, vector<int>& x1, vector<int>& x2, vector<int>& vv){
cl();
for (int i: x2) w[i] = 1;
int ds = (int) ((ask(w) + B - A - 1LL * dist * B) / (A - B));
vector<int> all;
for (int i: vv){
if (d[i] == ds){
all.pb(i);
}
}
while (all.size() > 1){
int k = (int) all.size() / 2;
cl();
for (int i = 0; i < k; i++){
add(v, all[i]);
}
ll sm = ask(w);
if (sm == (1LL * A * (dist - ds) + 1LL * B * ds)){
while (all.size() > k){
all.pop_back();
}
}
else {
reverse(all.begin(), all.end());
k = (int) all.size() - k;
while (all.size() > k) all.pop_back();
}
}
return (all[0] - 1);
};
answer(solve(U[x], d1, d2, t1), solve(V[x], d2, d1, t2));
}
Compilation message
highway.cpp: In lambda function:
highway.cpp:117:35: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
117 | while (all.size() > k){
| ~~~~~~~~~~~^~~
highway.cpp:124:35: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
124 | while (all.size() > k) all.pop_back();
| ~~~~~~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
10 ms |
2136 KB |
Output is correct |
3 |
Correct |
103 ms |
15804 KB |
Output is correct |
4 |
Correct |
99 ms |
15840 KB |
Output is correct |
5 |
Correct |
92 ms |
15804 KB |
Output is correct |
6 |
Correct |
104 ms |
15660 KB |
Output is correct |
7 |
Correct |
90 ms |
15792 KB |
Output is correct |
8 |
Correct |
102 ms |
15608 KB |
Output is correct |
9 |
Correct |
106 ms |
16260 KB |
Output is correct |
10 |
Correct |
90 ms |
16104 KB |
Output is correct |
11 |
Correct |
91 ms |
16560 KB |
Output is correct |
12 |
Correct |
100 ms |
17940 KB |
Output is correct |
13 |
Correct |
88 ms |
17080 KB |
Output is correct |
14 |
Correct |
95 ms |
17540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
2904 KB |
Output is correct |
2 |
Correct |
16 ms |
4892 KB |
Output is correct |
3 |
Correct |
25 ms |
7756 KB |
Output is correct |
4 |
Correct |
75 ms |
20028 KB |
Output is correct |
5 |
Correct |
71 ms |
20916 KB |
Output is correct |
6 |
Correct |
76 ms |
22912 KB |
Output is correct |
7 |
Correct |
75 ms |
23988 KB |
Output is correct |
8 |
Correct |
74 ms |
20560 KB |
Output is correct |
9 |
Correct |
72 ms |
22156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
600 KB |
Output is correct |
2 |
Correct |
10 ms |
2044 KB |
Output is correct |
3 |
Correct |
70 ms |
12404 KB |
Output is correct |
4 |
Correct |
88 ms |
15748 KB |
Output is correct |
5 |
Correct |
91 ms |
15580 KB |
Output is correct |
6 |
Correct |
81 ms |
15828 KB |
Output is correct |
7 |
Correct |
84 ms |
15712 KB |
Output is correct |
8 |
Correct |
82 ms |
15756 KB |
Output is correct |
9 |
Correct |
94 ms |
15372 KB |
Output is correct |
10 |
Correct |
92 ms |
15732 KB |
Output is correct |
11 |
Correct |
90 ms |
16536 KB |
Output is correct |
12 |
Correct |
99 ms |
17588 KB |
Output is correct |
13 |
Correct |
89 ms |
16812 KB |
Output is correct |
14 |
Correct |
90 ms |
17240 KB |
Output is correct |
15 |
Correct |
86 ms |
15588 KB |
Output is correct |
16 |
Correct |
83 ms |
15604 KB |
Output is correct |
17 |
Correct |
97 ms |
17120 KB |
Output is correct |
18 |
Correct |
89 ms |
17288 KB |
Output is correct |
19 |
Correct |
80 ms |
15712 KB |
Output is correct |
20 |
Correct |
90 ms |
18104 KB |
Output is correct |
21 |
Correct |
82 ms |
16676 KB |
Output is correct |
22 |
Correct |
87 ms |
16496 KB |
Output is correct |
23 |
Correct |
85 ms |
16164 KB |
Output is correct |
24 |
Correct |
96 ms |
16812 KB |
Output is correct |
25 |
Correct |
120 ms |
23168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
2136 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
2136 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |