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 <bits/stdc++.h>
#include "highway.h"
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
vector<pii> g[90005], g2[90005];
bool vis[90005];
int arr[2][90005];
int par[90005];
bool mark[130005];
int k = 1;
void dfs(int u, int p, int j, int d, int t){
par[u] = j;
if(p != -1) mark[j] = 1;
arr[t][k++] = u;
for(int i=0;i<g2[u].size();i++){
int v = g2[u][i].first, j = g2[u][i].second;
if(v == p) continue;
dfs(v, u, j, d+1, t);
}
}
void find_pair(int n, std::vector<int> U, std::vector<int> V, int a, int b){
int s, t;
int m = U.size();
for(int i=0;i<m;i++){
int a = U[i], b = V[i];
g[a].push_back(pii(b, i));
g[b].push_back(pii(a, i));
}
vector<int> w;
w.resize(m);
LL base = ask(w);
int lo = 0, hi = m-1, j = 0;
while(lo <= hi){
int mid = (lo+hi)/2;
for(int i=0;i<m;i++) w[i] = 0;
for(int i=0;i<=mid;i++) w[i] = 1;
LL tmp = ask(w);
if(tmp > base) j = mid, hi = mid-1;
else lo = mid+1;
}
int u = U[j], v = V[j];
vis[u] = 1;
vis[v] = 1;
queue<int> q;
q.push(u);
q.push(v);
while(!q.empty()){
int u = q.front();
q.pop();
for(int i=0;i<g[u].size();i++){
int v = g[u][i].first, j = g[u][i].second;
if(vis[v]) continue;
vis[v] = 1;
g2[u].push_back(pii(v, j));
g2[v].push_back(pii(u, j));
q.push(v);
}
}
mark[j] = 1;
k = 1;
dfs(u, -1, 0, 0, 0);
int sz1 = k-1;
k = 1;
dfs(v, -1, 0, 0, 1);
int sz2 = k-1;
s = u, t = v;
lo = 2, hi = sz1;
while(lo <= hi){
int mid = (lo+hi)/2;
for(int i=0;i<m;i++) w[i] = 0;
for(int i=mid;i<=sz1;i++){
int u = arr[0][i];
w[par[u]] = 1;
}
for(int j=0;j<m;j++){
if(mark[j]) continue;
w[j] = 1;
}
LL tmp = ask(w);
if(tmp > base) s = arr[0][mid], lo = mid+1;
else hi = mid-1;
}
lo = 2, hi = sz2;
while(lo <= hi){
int mid = (lo+hi)/2;
for(int i=0;i<m;i++) w[i] = 0;
for(int i=mid;i<=sz2;i++){
int u = arr[1][i];
w[par[u]] = 1;
}
for(int j=0;j<m;j++){
if(mark[j]) continue;
w[j] = 1;
}
LL tmp = ask(w);
if(tmp > base) t = arr[1][mid], lo = mid+1;
else hi = mid-1;
}
answer(s, t);
}
Compilation message (stderr)
highway.cpp: In function 'void dfs(int, int, int, int, int)':
highway.cpp:16:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<g2[u].size();i++){
~^~~~~~~~~~~~~
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:51:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<g[u].size();i++){
~^~~~~~~~~~~~
# | 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... |