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;
vector<pair<int, int> >v[90005];
bool vu[90005];
/*int ask(vector<int>w)
{
for(int i = 0; i < w.size(); i++)
cout << w[i] << ' ';
int x;
cin >> x;
return x;
}
void answer(int a, int b)
{
cout << "ANSWR:\n" << a << ' ' << b;
}*/
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
int M = U.size();
vector<int>w(M);
for(int i = 0; i < M; i++)
w[i]=0;
long long x=ask(w);
int l=0, r=M-1;
while(l != r)
{
int med=(l+r)/2;
for(int i = 0; i <= med; i++)
w[i]=1;
long long cu = ask(w);
if(cu!=x)
r=med;
else
l=med+1;
for(int i = 0; i <= med; i++)
w[i]=0;
}
//cout << l << '\n';
for(int i = 0; i < M; i++)
{
v[U[i]].push_back(make_pair(V[i], i));
v[V[i]].push_back(make_pair(U[i], i));
}
for(int i = 0; i < 90005; i++)
vu[i]=0;
vector<pair<int, int> >bfs;
vu[U[l]]=1;
for(int i = 0; i < v[U[l]].size(); i++)
{
if(v[U[l]][i].second!=l)
{
bfs.push_back(v[U[l]][i]);
vu[v[U[l]][i].first]=1;
}
}
for(int i = 0; i < bfs.size(); i++)
{
for(int j = 0; j < v[bfs[i].first].size(); j++)
{
if(!vu[v[bfs[i].first][j].first] && v[bfs[i].first][j].first != ((bfs[i].first^U[bfs[i].second])^V[bfs[i].second]))
{
bfs.push_back(v[bfs[i].first][j]);
//vu[v[bfs[i].first][j].first]=1;
}
}
}
/*for(int i = 0; i < bfs.size(); i++)
cout << bfs[i].first << ' ';
cout << '\n';*/
for(int i = 0; i < w.size(); i++)
w[i]=0;
for(int i = 0; i < bfs.size(); i++)
{
//cout << bfs[i].first << ' ';
vu[bfs[i].second]=1;
}
for(int i = 0; i < M; i++)
{
if(vu[U[i]] && vu[V[i]])
w[i]=1;
}
long long cu1=ask(w);
int node1, node2;
if(cu1==x)
{
node1=U[l];
}
else
{
int l1=0;
int r1=bfs.size()-1;
while(l1 != r1)
{
int med=(l1+r1)/2;
for(int i = 0; i <= med; i++)
w[bfs[i].second]=0;
long long cu11=ask(w);
if(cu11==x)
r1=med;
else
l1=med+1;
for(int i = 0; i <= med; i++)
w[bfs[i].second]=1;
}
node1=bfs[l1].first;
}
bfs.clear();
for(int i = 0; i < 90005; i++)
vu[i]=0;
vu[V[l]]=1;
for(int i = 0; i < v[V[l]].size(); i++)
{
if(v[V[l]][i].second != l)
{
bfs.push_back(v[V[l]][i]);
}
}
for(int i = 0; i < bfs.size(); i++)
{
for(int j = 0; j < v[bfs[i].first].size(); j++)
{
if(!vu[v[bfs[i].first][j].first] && v[bfs[i].first][j].first != (bfs[i].first^U[bfs[i].second]^V[bfs[i].second]))
{
bfs.push_back(v[bfs[i].first][j]);
}
}
}
for(int i = 0; i < bfs.size(); i++)
{
//cout << bfs[i].first << ' ';
vu[bfs[i].second]=1;
}
//cout << '\n';
for(int i = 0; i < w.size(); i++)
w[i]=0;
for(int i = 0; i < M; i++)
{
if(vu[U[i]] && vu[V[i]])
w[i]=1;
}
//cout << "here\n";
cu1=ask(w);
if(cu1==x)
{
node2=V[l];
}
else
{
int l1=0;
int r1=bfs.size()-1;
while(l1 != r1)
{
int med=(l1+r1)/2;
for(int i = 0; i <= med; i++)
w[bfs[i].second]=0;
long long cu11=ask(w);
if(cu11==x)
r1=med;
else
l1=med+1;
for(int i = 0; i <= med; i++)
w[bfs[i].second]=1;
}
node2=bfs[l1].first;
}
answer(node1, node2);
}
/*int main()
{
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
find_pair(7, {0, 1, 2, 5, 7, 5, 3, 3}, {2, 2, 5, 8, 5, 6, 2, 4}, 1, 2);
}*/
Compilation message (stderr)
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:50:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(int i = 0; i < v[U[l]].size(); i++)
| ~~^~~~~~~~~~~~~~~~
highway.cpp:58:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for(int i = 0; i < bfs.size(); i++)
| ~~^~~~~~~~~~~~
highway.cpp:60:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for(int j = 0; j < v[bfs[i].first].size(); j++)
| ~~^~~~~~~~~~~~~~~~~~~~~~~~
highway.cpp:72:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
72 | for(int i = 0; i < w.size(); i++)
| ~~^~~~~~~~~~
highway.cpp:74:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | for(int i = 0; i < bfs.size(); i++)
| ~~^~~~~~~~~~~~
highway.cpp:113:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
113 | for(int i = 0; i < v[V[l]].size(); i++)
| ~~^~~~~~~~~~~~~~~~
highway.cpp:120:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
120 | for(int i = 0; i < bfs.size(); i++)
| ~~^~~~~~~~~~~~
highway.cpp:122:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
122 | for(int j = 0; j < v[bfs[i].first].size(); j++)
| ~~^~~~~~~~~~~~~~~~~~~~~~~~
highway.cpp:130:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
130 | for(int i = 0; i < bfs.size(); i++)
| ~~^~~~~~~~~~~~
highway.cpp:136:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
136 | for(int i = 0; i < w.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... |