#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
struct node {
int p;
vector<pair<node*, int>> l;
int d, id;
};
void dfs(node* n, node* p, int d){
n->d = d;
for(auto [c,x] : n->l){
if(c==p) continue;
c->p = x;
dfs(c, n, d+1);
}
}
void zfs(node* n, node* p, vector<node*>& o){
for(auto [c,x] : n->l){
if(c!=p) zfs(c, n, o);
}
o.push_back(n);
}
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
node g[N];
int m = U.size();
bool tsub = true;
for(int i = 0;i < U.size();i++){
tsub &= U[i]==i && V[i]==i+1;
g[U[i]].l.emplace_back(&g[V[i]], i);
g[V[i]].l.emplace_back(&g[U[i]], i);
}
for(int i = 0;i < N;i++) g[i].id = i;
vector<int> w(m, 0);vector<node*> o;
zfs(&g[0], NULL, o);
long long dis = ask(w)/A;
int l = 0, r = N-1, mid;
while(l<r){
mid=l+r>>1;
for(int i = l;i <= mid;i++){
for(auto [c,x] : o[i]->l) w[x]=1;
}
long long re = ask(w);
for(int i = l;i <= mid;i++){
for(auto [c,x] : o[i]->l) w[x]=0;
}
if(re>dis*A){
r = mid;
} else {
l=mid+1;
}
}
int s = o[l]->id;
dfs(o[l], NULL, 0);
vector<pair<int, int>> v;
for(int i = 0;i < N;i++) if(g[i].d == dis) v.emplace_back(g[i].p, i);
l = 0; r = v.size()-1;
while(l<r){
mid = l+r>>1;
for(int i = l;i <= mid;i++) w[v[i].first] = 1;
long long re = ask(w);
for(int i = l;i <= mid;i++) w[v[i].first] = 0;
if(re > dis*A){
r = mid;
} else l = mid+1;
}
answer(s, v[l].second);
}
Compilation message
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:27:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for(int i = 0;i < U.size();i++){
| ~~^~~~~~~~~~
highway.cpp:38:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
38 | mid=l+r>>1;
| ~^~
highway.cpp:58:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
58 | mid = l+r>>1;
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 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 |
0 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 |
344 KB |
Output is correct |
2 |
Correct |
8 ms |
1624 KB |
Output is correct |
3 |
Correct |
87 ms |
11464 KB |
Output is correct |
4 |
Correct |
86 ms |
11648 KB |
Output is correct |
5 |
Correct |
80 ms |
11464 KB |
Output is correct |
6 |
Correct |
81 ms |
11480 KB |
Output is correct |
7 |
Correct |
80 ms |
11464 KB |
Output is correct |
8 |
Correct |
83 ms |
11464 KB |
Output is correct |
9 |
Correct |
80 ms |
11484 KB |
Output is correct |
10 |
Correct |
81 ms |
11424 KB |
Output is correct |
11 |
Correct |
80 ms |
12764 KB |
Output is correct |
12 |
Correct |
78 ms |
13272 KB |
Output is correct |
13 |
Correct |
79 ms |
13012 KB |
Output is correct |
14 |
Correct |
93 ms |
12248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
2136 KB |
Output is correct |
2 |
Correct |
16 ms |
4184 KB |
Output is correct |
3 |
Correct |
23 ms |
5844 KB |
Output is correct |
4 |
Correct |
72 ms |
16604 KB |
Output is correct |
5 |
Correct |
67 ms |
16584 KB |
Output is correct |
6 |
Correct |
61 ms |
16588 KB |
Output is correct |
7 |
Correct |
66 ms |
16612 KB |
Output is correct |
8 |
Correct |
73 ms |
16596 KB |
Output is correct |
9 |
Correct |
67 ms |
16616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
8 ms |
1624 KB |
Output is correct |
3 |
Correct |
55 ms |
9280 KB |
Output is correct |
4 |
Correct |
80 ms |
11476 KB |
Output is correct |
5 |
Correct |
89 ms |
11464 KB |
Output is correct |
6 |
Correct |
82 ms |
11472 KB |
Output is correct |
7 |
Correct |
74 ms |
11240 KB |
Output is correct |
8 |
Correct |
75 ms |
11472 KB |
Output is correct |
9 |
Correct |
82 ms |
11464 KB |
Output is correct |
10 |
Correct |
98 ms |
11476 KB |
Output is correct |
11 |
Correct |
74 ms |
12236 KB |
Output is correct |
12 |
Correct |
91 ms |
13512 KB |
Output is correct |
13 |
Correct |
87 ms |
13016 KB |
Output is correct |
14 |
Correct |
86 ms |
13544 KB |
Output is correct |
15 |
Correct |
86 ms |
11484 KB |
Output is correct |
16 |
Correct |
69 ms |
11464 KB |
Output is correct |
17 |
Correct |
89 ms |
13036 KB |
Output is correct |
18 |
Correct |
81 ms |
12744 KB |
Output is correct |
19 |
Correct |
71 ms |
11480 KB |
Output is correct |
20 |
Correct |
75 ms |
13784 KB |
Output is correct |
21 |
Correct |
70 ms |
12736 KB |
Output is correct |
22 |
Correct |
77 ms |
12736 KB |
Output is correct |
23 |
Correct |
80 ms |
11584 KB |
Output is correct |
24 |
Correct |
77 ms |
12340 KB |
Output is correct |
25 |
Correct |
109 ms |
16080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
201 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
200 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |