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;
typedef long long ll;
typedef pair<int,int> pi;
#define F first
#define S second
#define endl '\n'
#define all(x) (x).begin(),(x).end()
const ll INF = 1e18;
const int N = 3e5+1;
vector<vector<pi> > a(100000);
vector<int> ans;
int d[100000],dep,maxi[100000];
void dfs(int s, int e){
maxi[s] = d[s];
if(d[s]==dep)ans.push_back(s);
for(auto x : a[s])
if(x.F!=e){
d[x.F] = d[s]+1;
dfs(x.F,s);
maxi[s] = max(maxi[s],maxi[x.F]);
}
}
vector<int> q;
ll cost[2],ini;
void solve(int s, int e){
if(d[s]==dep){
answer(0,s);
return;
}
vector<pi> curr;
for(auto x : a[s])
if(x.F!=e && maxi[x.F]>=dep){
curr.push_back(x);
}
//for(auto x : curr)
// cout<<x.F<<" "<<x.S<<endl;
assert(!curr.empty());
int l = 0,r = curr.size()-1;
int ans,i;
while(l<=r){
int mid = (l+r)/2;
for(i=0;i<=mid;i++){
q[curr[i].S] = 1;
}
ll now = ask(q);
for(i=0;i<=mid;i++){
q[curr[i].S] = 0;
}
if(now!=ini){
r = mid-1;
ans = mid;
}
else
l = mid+1;
}
solve(curr[ans].F,s);
}
void find_pair(int n, vector<int> u, vector<int> v, int A, int B) {
int m = u.size();
int i;
cost[0] = A;
cost[1] = B;
for(i=0;i<m;i++){
int x = v[i];
int y = u[i];
a[x].push_back({y,i});
a[y].push_back({x,i});
}
q.assign(m,0);
ll tot = ask(q);
dep = tot/A;
//p2(tot,dep)
//cout<<tot<<" "<<dep<<endl;
//cout<<endl;
ini = tot;
dfs(0,0);
//for(i=0;i<n;i++){
// cout<<d[i]<<" "<<maxi[i]<<endl;
//}cout<<endl;
solve(0,0);
/*
16 15 3 5 0 14
0 1
0 2
0 3
1 4
1 5
4 6
4 7
2 8
8 9
9 10
3 11
3 12
11 14
11 15
12 13
*/
}
Compilation message (stderr)
highway.cpp: In function 'void solve(int, int)':
highway.cpp:63:19: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
63 | solve(curr[ans].F,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... |