///~~~LOTA~~~///
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define append push_back
#define add insert
#define nl '\n'
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(x) (x).begin(),(x).end()
#define L0TA ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define terminator main
#define N 90000
int d;
int ve[N];
int par[N];
int dept[N];
vector<pii> e[N];
vector<int> x[N];
void dfs(int v,int u){
d=max(d,dept[v]);
x[dept[v]].append(v);
for(auto& i:e[v]){
if(i.ff==u)
continue;
dept[i.ff]=dept[v]+1;
ve[i.ff]=i.ss;
par[i.ff]=v;
dfs(i.ff,v);
}
}
void find_pair(int n,vector<int> v,vector<int> u,int a,int b){
ll m,o,p,q,r,s,t;
vector<int> h;
for(int i=1;i<n;i++)
h.append(0);
for(int i=m=d=0;i<n-1;i++){
e[v[i]].append({u[i],i});
e[u[i]].append({v[i],i});
}
o=ask(h);
m=(o/a)*b;
dfs(0,-1);
q=d;
for(int i=65536;i>0;i/=2){
if(i>=q) continue;
for(int j=1;j<=q-i;j++)
for(auto& k:x[j])
h[ve[k]]=1;
r=ask(h);
for(int j=1;j<=q-i;j++)
for(auto& k:x[j])
h[ve[k]]=0;
if(r==m) q-=i;
}
p=q;
for(int i=65536;i>0;i/=2){
if(i>p) continue;
for(auto& j:x[p-i+1])
h[ve[j]]=1;
r=ask(h);
for(auto& j:x[p-i+1])
h[ve[j]]=0;
if(r-o==b-a) p-=i;
}
s=t=0;
for(int i=65536;i>0;i/=2){
if(s+i>x[q].size())
continue;
for(int j=0;j<s+i;j++)
h[ve[x[q][j]]]=1;
r=ask(h);
for(int j=0;j<s+i;j++)
h[ve[x[q][j]]]=0;
if(r==o) s+=i;
}
s=q=x[q][s];
while(dept[q]>p)
q=par[q];
if(p==m){
answer(s,q);
return;
}
for(int i=65536;i>0;i/=2){
if(t+i>x[p].size())
continue;
for(int j=0;j<t+i;j++)
h[ve[x[p][j]]]=1;
h[ve[q]]=0;
r=ask(h);
for(int j=0;j<t+i;j++)
h[ve[x[p][j]]]=0;
if(r==o) t+=i;
}
t=x[p][t];
answer(s,t);
}
Compilation message
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:72:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | if(s+i>x[q].size())
| ~~~^~~~~~~~~~~~
highway.cpp:89:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
89 | if(t+i>x[p].size())
| ~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4440 KB |
Output is correct |
2 |
Correct |
2 ms |
4440 KB |
Output is correct |
3 |
Correct |
3 ms |
4440 KB |
Output is correct |
4 |
Correct |
2 ms |
4440 KB |
Output is correct |
5 |
Correct |
2 ms |
4440 KB |
Output is correct |
6 |
Correct |
2 ms |
4696 KB |
Output is correct |
7 |
Correct |
2 ms |
4696 KB |
Output is correct |
8 |
Correct |
2 ms |
4696 KB |
Output is correct |
9 |
Correct |
2 ms |
4692 KB |
Output is correct |
10 |
Correct |
3 ms |
4440 KB |
Output is correct |
11 |
Correct |
2 ms |
4440 KB |
Output is correct |
12 |
Correct |
2 ms |
4696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4696 KB |
Output is correct |
2 |
Correct |
10 ms |
5260 KB |
Output is correct |
3 |
Correct |
77 ms |
11564 KB |
Output is correct |
4 |
Correct |
86 ms |
11400 KB |
Output is correct |
5 |
Correct |
80 ms |
11892 KB |
Output is correct |
6 |
Correct |
78 ms |
11356 KB |
Output is correct |
7 |
Correct |
73 ms |
11364 KB |
Output is correct |
8 |
Correct |
72 ms |
11912 KB |
Output is correct |
9 |
Correct |
65 ms |
11372 KB |
Output is correct |
10 |
Correct |
77 ms |
11392 KB |
Output is correct |
11 |
Correct |
82 ms |
12884 KB |
Output is correct |
12 |
Correct |
83 ms |
13880 KB |
Output is correct |
13 |
Correct |
87 ms |
13080 KB |
Output is correct |
14 |
Correct |
81 ms |
12172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
6228 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
2 |
Correct |
9 ms |
5252 KB |
Output is correct |
3 |
Correct |
64 ms |
9896 KB |
Output is correct |
4 |
Correct |
79 ms |
11508 KB |
Output is correct |
5 |
Incorrect |
89 ms |
11396 KB |
Output is incorrect: {s, t} is wrong. |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
5208 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
5208 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |