#include "highway.h"
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 150100;
int n, m;
vector<int>w;
vector<int>gs[maxn];
vector<pair<int,int> > g[maxn];
vector<int>gt[maxn];
int dist[maxn][2], parent[maxn][2];
int pind[maxn], x;
bool visited[maxn];
ll dista;
int type[maxn];
bool important[maxn];
vector<pair<int,int> > st[2];
void bfs(int u, int v) {
visited[u] = visited[v] = true;
queue<pair<int,int> > q;
type[u] = 0;
type[v] = 1;
q.push(mp(u, 0));
q.push(mp(v, 1));
pind[u] = pind[v] = -1;
st[0].pb(mp(u, x));
st[1].pb(mp(v, x));
while(!q.empty()) {
int curr = q.front().first;
int currtype = q.front().second;
q.pop();
for(auto i:g[curr]) {
int ni = i.first, nind = i.second;
if(visited[ni]) continue;
visited[ni] = true;
pind[ni] = nind;
important[nind] = true;
q.push(mp(ni, currtype));
st[currtype].pb(mp(ni, nind));
}
}
}
int solve(int root, int d) {
int li = 0;
int ri = st[d].size() - 1;
int answ = li;
//cout<<d<<": \n";
while(li <= ri) {
int mid = (li + ri) / 2;
vector<int>w(m, 0);
for(int i=mid;i<st[d].size();i++) {
w[st[d][i].second] = 1;
}
for(int i=0;i<m;i++) {
if(!important[i]) w[i] = 1;
}
ll currdist = ask(w);
//cout<<mid<<": "<<currdist<<"\n";
if(currdist == dista) {
ri = mid - 1;
}
else {
li = mid + 1;
answ = max(answ, mid);
}
}
return st[d][answ].first;
}
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
n = N; m = U.size();
int li=0, ri=m-1;
for(int i=0;i<m;i++) {
//ind[mp(U[i], V[i])] = ind[mp(V[i], U[i])] = i;
gs[U[i]].pb(V[i]);
gs[V[i]].pb(U[i]);
g[U[i]].pb(mp(V[i], i));
g[V[i]].pb(mp(U[i], i));
w.pb(0);
}
dista = ask(w);
while(li < ri) {
int mid = (li + ri) / 2;
for(int i=0;i<mid;i++) {
w[i] = 1;
}
ll currdist = ask(w);
//cout<<li<<", "<<ri<<" - "<<mid<<": "<<currdist<<"\n";
for(int i=0;i<mid;i++) {
w[i] = 0;
}
if(currdist == dista) {
li = mid;
}
else {
ri = mid - 1;
}
}
x = li;
int u = U[x], v = V[x];
important[x] = true;
//cout<<u<<" "<<v<<"\n";
bfs(u, v);
//preprocess();
//memset(visited,false,sizeof(visited));
//cout<<"Ans: "<<xx<<" "<<yy<<"\n";
answer(solve(u, 0), solve(v, 1));
}
Compilation message
highway.cpp: In function 'int solve(int, int)':
highway.cpp:70:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=mid;i<st[d].size();i++) {
~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
10904 KB |
Output is incorrect: more than 100 calls to ask. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
10988 KB |
Output is correct |
2 |
Incorrect |
35 ms |
11768 KB |
Output is incorrect: more than 100 calls to ask. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
25 ms |
11612 KB |
Output is incorrect: more than 100 calls to ask. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
10980 KB |
Output is correct |
2 |
Incorrect |
34 ms |
11736 KB |
Output is incorrect: more than 100 calls to ask. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
11968 KB |
Output is correct |
2 |
Incorrect |
32 ms |
11896 KB |
Output is incorrect: more than 100 calls to ask. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
11964 KB |
Output is correct |
2 |
Correct |
40 ms |
12128 KB |
Output is correct |
3 |
Incorrect |
213 ms |
19376 KB |
Output is incorrect: more than 100 calls to ask. |
4 |
Halted |
0 ms |
0 KB |
- |