#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define all(a) (a).begin(), (a).end()
template<typename T>
int len(T &a){
return a.size();
}
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
vector<vector<int>> g;
vector<int> u, v;
int n, m;
vector<int> nodes, ch;
void dfs(int tar, int i, int p = -1, int d = 0){
for(auto j : g[i]){
int x = u[j] ^ v[j] ^ i;
if(x == p) continue;
if(d + 1 == tar){
nodes.push_back(j);
ch.push_back(x);
}else{
dfs(tar, x, i, d + 1);
}
}
}
void find_pair(int N, std::vector<int> U, std::vector<int> V, int a, int b) {
n = N;
u = U;
v = V;
m = len(v);
g.resize(n);
for(int i = 0; i < m; i ++){
g[u[i]].push_back(i);
g[v[i]].push_back(i);
}
vector<int> w(m, 1);
ll d = ask(w) / b;
queue<int> q;
q.push(0);
vector<int> vis(n);
vector<int> ord;
vis[0] = 1;
while(!q.empty()){
int t = q.front(); q.pop();
for(auto j : g[t]){
int x = u[j] ^ v[j] ^ t;
if(vis[x]) continue;
ord.push_back(j);
ch.push_back(x);
vis[x] = 1;
q.push(x);
}
}
int l = -2, r = n - 2;
while(r - l > 1){
int mid = (l + r) / 2;
for(int j = 0; j <= mid; j ++){
w[ord[j]] = 0;
}
for(int j = mid + 1; j < n - 1; j ++) w[ord[j]] = 1;
if(d * a == ask(w)){
r = mid;
}else l = mid;
}
int s = (r == -1 ? 0 : ch[r]);
ch.clear();
dfs(d, s);
l = -1, r = len(ch) - 1;
w.assign(m, 1);
while(r - l > 1){
int mid = (l + r) / 2;
for(int j = 0; j <= mid; j ++){
w[nodes[j]] = 0;
}
for(int j = mid + 1; j < len(ch); j ++){
w[nodes[j]] = 1;
}
if(ask(w) != d * b){
r = mid;
}else l = mid;
}
answer(s, ch[r]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 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 |
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 |
520 KB |
Output is correct |
2 |
Correct |
8 ms |
1528 KB |
Output is correct |
3 |
Correct |
79 ms |
9196 KB |
Output is correct |
4 |
Correct |
82 ms |
9248 KB |
Output is correct |
5 |
Correct |
96 ms |
9300 KB |
Output is correct |
6 |
Correct |
85 ms |
9296 KB |
Output is correct |
7 |
Correct |
80 ms |
9304 KB |
Output is correct |
8 |
Correct |
75 ms |
9684 KB |
Output is correct |
9 |
Correct |
83 ms |
9300 KB |
Output is correct |
10 |
Correct |
77 ms |
9292 KB |
Output is correct |
11 |
Correct |
71 ms |
9692 KB |
Output is correct |
12 |
Correct |
95 ms |
10148 KB |
Output is correct |
13 |
Correct |
73 ms |
9964 KB |
Output is correct |
14 |
Correct |
77 ms |
10280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1368 KB |
Output is correct |
2 |
Correct |
13 ms |
2592 KB |
Output is correct |
3 |
Correct |
19 ms |
3156 KB |
Output is correct |
4 |
Correct |
65 ms |
10800 KB |
Output is correct |
5 |
Correct |
57 ms |
9108 KB |
Output is correct |
6 |
Correct |
64 ms |
14440 KB |
Output is correct |
7 |
Correct |
64 ms |
9176 KB |
Output is correct |
8 |
Correct |
71 ms |
12148 KB |
Output is correct |
9 |
Correct |
58 ms |
9188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
8 ms |
1480 KB |
Output is correct |
3 |
Correct |
58 ms |
7428 KB |
Output is correct |
4 |
Correct |
80 ms |
9448 KB |
Output is correct |
5 |
Correct |
78 ms |
9292 KB |
Output is correct |
6 |
Correct |
76 ms |
9296 KB |
Output is correct |
7 |
Correct |
84 ms |
9300 KB |
Output is correct |
8 |
Correct |
76 ms |
9176 KB |
Output is correct |
9 |
Correct |
77 ms |
9188 KB |
Output is correct |
10 |
Correct |
86 ms |
9288 KB |
Output is correct |
11 |
Correct |
73 ms |
9968 KB |
Output is correct |
12 |
Correct |
92 ms |
11112 KB |
Output is correct |
13 |
Correct |
75 ms |
10196 KB |
Output is correct |
14 |
Correct |
74 ms |
9984 KB |
Output is correct |
15 |
Correct |
69 ms |
9288 KB |
Output is correct |
16 |
Correct |
74 ms |
9240 KB |
Output is correct |
17 |
Correct |
79 ms |
10176 KB |
Output is correct |
18 |
Correct |
81 ms |
10132 KB |
Output is correct |
19 |
Correct |
74 ms |
9228 KB |
Output is correct |
20 |
Correct |
70 ms |
9168 KB |
Output is correct |
21 |
Correct |
70 ms |
10428 KB |
Output is correct |
22 |
Correct |
72 ms |
10228 KB |
Output is correct |
23 |
Correct |
91 ms |
9844 KB |
Output is correct |
24 |
Correct |
71 ms |
10660 KB |
Output is correct |
25 |
Correct |
93 ms |
16608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
1648 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
1368 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |