#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
#define isz(a) ((signed)a.size())
using ll = long long;
struct edge_t{
int u, v;
};
const int N = 90'000 + 5, M = 130'000 + 5;
int n, m;
int a, b;
vector <edge_t> edge;
vector <int> adj[N];
vector <int> vquery;
namespace subtask1234{
bool check(){
return m == n - 1;
}
int length_path;
int pv[N];
int pe[N];
int ctrtour, tour[N];
void dfs_tour(int u){
tour[ctrtour] = u;
ctrtour++;
for (auto i: adj[u]){
if (i == pe[u]){
continue;
}
auto v = u ^ edge[i].u ^ edge[i].v;
pv[v] = u;
pe[v] = i;
dfs_tour(v);
}
}
int solve_fixed(int s){
pv[s] = -1;
pe[s] = -1;
ctrtour = 0;
dfs_tour(s);
int lo = 1, hi = n - 1;
while (lo < hi){
int mid = (lo + hi) >> 1;
fill(vquery.begin(), vquery.end(), 0);
for (int pos = 1; pos <= mid; pos++){
vquery[pe[tour[pos]]] = 1;
}
if (ask(vquery) == (ll)length_path * b){
hi = mid;
}
else{
lo = mid + 1;
}
}
return tour[lo];
}
int depth[N];
void dfs_depth(int u){
for (auto i: adj[u]){
if (i == pe[u]){
continue;
}
int v = u ^ edge[i].u ^ edge[i].v;
pv[v] = u;
pe[v] = i;
depth[v] = depth[u] + 1;
dfs_depth(v);
}
}
int find_one(){
int root = 1;
pv[root] = -1;
pe[root] = -1;
depth[root] = 0;
dfs_depth(root);
int lo = 1, hi = *max_element(depth, depth + n);
while (lo < hi){
int mid = (lo + hi + 1) >> 1;
fill(vquery.begin(), vquery.end(), 0);
for (int u = 0; u < n; u++){
if (depth[u] >= mid){
vquery[pe[u]] = 1;
}
}
if (ask(vquery) == (ll)length_path * a){
hi = mid - 1;
}
else{
lo = mid;
}
}
vector <int> layer;
for (int u = 0; u < n; u++){
if (depth[u] == lo){
layer.emplace_back(u);
}
}
lo = 0; hi = isz(layer) - 1;
while (lo < hi){
int mid = (lo + hi) >> 1;
fill(vquery.begin(), vquery.end(), 0);
for (int i = 0; i <= mid; i++){
vquery[pe[layer[i]]] = 1;
}
if (ask(vquery) == (ll)length_path * a){
lo = mid + 1;
}
else{
hi = mid;
}
}
return layer[lo];
}
void solve(){
fill(vquery.begin(), vquery.end(), 0);
length_path = ask(vquery) / a;
int s = find_one();
int t = solve_fixed(s);
answer(s, t);
}
}
void find_pair(int _n, vector <int> _u, vector <int> _v, int _a, int _b){
n = _n;
m = isz(_u);
edge.resize(m);
for (int i = 0; i < m; i++){
int u = _u[i], v = _v[i];
edge[i] = edge_t{u, v};
adj[u].emplace_back(i);
adj[v].emplace_back(i);
}
a = _a;
b = _b;
vquery.resize(m);
if (subtask1234::check()){
subtask1234::solve();
return;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
1 ms |
2384 KB |
Output is correct |
4 |
Correct |
1 ms |
2420 KB |
Output is correct |
5 |
Correct |
1 ms |
2384 KB |
Output is correct |
6 |
Correct |
2 ms |
2384 KB |
Output is correct |
7 |
Correct |
1 ms |
2432 KB |
Output is correct |
8 |
Correct |
1 ms |
2384 KB |
Output is correct |
9 |
Correct |
2 ms |
2384 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
1 ms |
2428 KB |
Output is correct |
12 |
Correct |
1 ms |
2384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2384 KB |
Output is correct |
2 |
Correct |
9 ms |
3160 KB |
Output is correct |
3 |
Correct |
110 ms |
9324 KB |
Output is correct |
4 |
Correct |
97 ms |
9316 KB |
Output is correct |
5 |
Correct |
110 ms |
9340 KB |
Output is correct |
6 |
Correct |
121 ms |
9244 KB |
Output is correct |
7 |
Correct |
100 ms |
9316 KB |
Output is correct |
8 |
Correct |
79 ms |
9320 KB |
Output is correct |
9 |
Correct |
95 ms |
9312 KB |
Output is correct |
10 |
Correct |
103 ms |
9212 KB |
Output is correct |
11 |
Correct |
114 ms |
10664 KB |
Output is correct |
12 |
Correct |
106 ms |
11256 KB |
Output is correct |
13 |
Correct |
98 ms |
10772 KB |
Output is correct |
14 |
Correct |
117 ms |
10708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
3792 KB |
Output is correct |
2 |
Correct |
13 ms |
5156 KB |
Output is correct |
3 |
Correct |
31 ms |
6488 KB |
Output is correct |
4 |
Correct |
82 ms |
14704 KB |
Output is correct |
5 |
Correct |
82 ms |
14684 KB |
Output is correct |
6 |
Correct |
83 ms |
14736 KB |
Output is correct |
7 |
Correct |
149 ms |
14768 KB |
Output is correct |
8 |
Correct |
77 ms |
14740 KB |
Output is correct |
9 |
Correct |
78 ms |
14640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2384 KB |
Output is correct |
2 |
Correct |
8 ms |
3152 KB |
Output is correct |
3 |
Correct |
68 ms |
7792 KB |
Output is correct |
4 |
Correct |
99 ms |
9256 KB |
Output is correct |
5 |
Correct |
90 ms |
9328 KB |
Output is correct |
6 |
Correct |
73 ms |
9212 KB |
Output is correct |
7 |
Correct |
99 ms |
9232 KB |
Output is correct |
8 |
Correct |
114 ms |
9328 KB |
Output is correct |
9 |
Correct |
132 ms |
9312 KB |
Output is correct |
10 |
Correct |
94 ms |
9320 KB |
Output is correct |
11 |
Correct |
111 ms |
10332 KB |
Output is correct |
12 |
Correct |
106 ms |
10988 KB |
Output is correct |
13 |
Correct |
132 ms |
10728 KB |
Output is correct |
14 |
Correct |
143 ms |
11120 KB |
Output is correct |
15 |
Correct |
94 ms |
9212 KB |
Output is correct |
16 |
Correct |
68 ms |
9220 KB |
Output is correct |
17 |
Correct |
98 ms |
10428 KB |
Output is correct |
18 |
Correct |
100 ms |
10920 KB |
Output is correct |
19 |
Correct |
86 ms |
9260 KB |
Output is correct |
20 |
Correct |
132 ms |
11588 KB |
Output is correct |
21 |
Correct |
81 ms |
9868 KB |
Output is correct |
22 |
Correct |
76 ms |
9868 KB |
Output is correct |
23 |
Correct |
100 ms |
9784 KB |
Output is correct |
24 |
Correct |
110 ms |
10180 KB |
Output is correct |
25 |
Correct |
130 ms |
14220 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
3024 KB |
Output is incorrect: answered not exactly once. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
3016 KB |
Output is incorrect: answered not exactly once. |
2 |
Halted |
0 ms |
0 KB |
- |