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 <vector>
#include <iostream>
#include <map>
#include "highway.h"
using namespace std;
int const MAXN=1e5;
vector<int>w;
long long dis=0;
vector<int>d;
vector<int>ind;
vector<pair<int,int>>nei[MAXN]={};
int B1,A1;
void dfs(int u,int p=-1)
{
for (auto [i,in]:nei[u])
{
if (i==p)
continue;
ind.push_back(in);
dfs(i,u);
}
}
void divi(int st,int en,int cnt)
{
if (cnt==0)
return;
if (en-st+1==cnt)
{
for (int i=st;i<=en;i++)
d.push_back(ind[i]);
return;
}
int mid=(st+en)/2;
for (int i=st;i<=mid;i++)
w[ind[i]]=1;
long long g=ask(w);
for (int i=st;i<=mid;i++)
w[ind[i]]=0;
int f=(g-dis)/(B1-A1);
if (f)
divi(st,mid,f);
if (cnt-f)
divi(mid+1,en,cnt-f);
}
void find_pair(int N, vector<int> U, vector<int> V, int A, int B)
{
A1=A,B1=B;
int m=U.size();
for (int i=0;i<m;i++)
{
nei[U[i]].push_back({V[i],i});
nei[V[i]].push_back({U[i],i});
}
dfs(1);
for (int i=0;i<m;i++)
w.push_back(0);
dis=ask(w);
divi(0,m-1,dis/A1);
map<int,int>cnt;
for (auto i:d)
cnt[U[i]]++,cnt[V[i]]++;
vector<int>ans;
for (auto i:cnt)
if (i.second==1)
ans.push_back(i.first);
answer(ans[0],ans[1]);
}
# | 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... |