This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<n;++i)
#define ll long long
#define pb push_back
#define all(x) x.begin(), x.end()
const ll inf = 1e18;
#define pi pair<int,int>
#define f first
#define s second
const int maxn=1e5;
vector<pi> adj[maxn];
pi e[maxn];
vector<int> z;
void dfs(int u, int p) {
for(auto&ed:adj[u]) {
int v=ed.f, i=ed.s;
if (v==p) continue;
e[i]={u,v};
z.pb(i);
dfs(v,u);
}
}
void find_pair(int n, vector<int>u, vector<int>v, int a, int b) {
int m=u.size();
if (m!=n-1) exit(0);
forn(i,n-1) adj[u[i]].pb({v[i],i}), adj[v[i]].pb({u[i],i});
int k=0; forn(i,n) if (adj[i].size()==1) k=i;
dfs(k,-1);
ll s = ask(vector<int>(m,0));
int l=0, r=n-2;
while (l<r) {
int m=(l+r)>>1;
vector<int> q(n-1);
forn(i,m+1) q[z[i]]=1;
ll x=ask(q);
if (x==s/a*b) r=m;
else l=m+1;
}
k = e[z[r]].s;
//k=0;
z.clear();
dfs(k,-1);
l=0, r=n-2;
while (l<r) {
int m=(l+r)>>1;
vector<int> q(n-1);
forn(i,m+1) q[z[i]]=1;
ll x=ask(q);
if (x==s/a*b) r=m;
else l=m+1;
}
answer(k,e[z[r]].s);
}
# | 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... |