이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void answer(int s, int t);
long long ask(const vector<int> &w);
int const MAXN=90005;
vector<pair<int,int>> adj[MAXN];
int par_ind[MAXN];
int dep[MAXN];
vector<int> di[MAXN];
int n,a,b,m;
vector<int> col;
void dfs(int node,int par){
dep[node]=dep[par]+1;
di[dep[node]].push_back(node);
for(auto [i,e]:adj[node])
if(i!=par){
par_ind[i]=e;
dfs(i,node);
}
}
int solve(int s){
for (int i = 0; i < n; ++i){
di[i].clear();
dep[i]=0;
}
dfs(s,0);
ll sm=ask(col);
ll k=sm/a;
k++;
int ln=di[k].size();
int low=0,high=ln;
while(high-low>1){
int mid=(high+low)/2;
for(int i=0;i<m;i++)
col[i]=0;
for(int i=low;i<mid;i++)
col[par_ind[di[k][i]]]=1;
if(ask(col)>sm)
high=mid;
else
low=mid;
}
return di[k][low];
}
int pre_solver(){
dfs(0,0);
ll sm=ask(col);
ll k=sm/a;
k++;
int low=2,high=n;
while(high-low>1){
int mid=(high+low)/2;
for(int i=0;i<m;i++)
col[i]=0;
for(int i=mid;i<high;i++)
for(int j:di[i])
col[par_ind[j]]=1;
if(ask(col)>sm)
low=mid;
else
high=mid;
}
return di[low][0];
}
void find_pair(int nn, vector<int> U, vector<int> V, int A, int B){
// cout<<"In"<<endl;
n=nn;
a=A;
b=B;
m=U.size();
if(m!=n-1)
return;
col.resize(m);
for(int i=0;i<m;i++){
col[i]=0;
adj[U[i]].push_back({V[i],i});
adj[V[i]].push_back({U[i],i});
}
int s=pre_solver();
int t=solve(s);
// cout<<s<<' '<<t<<endl;
answer(s,t);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |