#include "highway.h"
#include<bits/stdc++.h>
using namespace std;
const int MAXN=9e4+6;
const int MAXM=(1<<17);
vector<pair<int,int> >g[MAXN];
int distu[MAXN],distv[MAXN];
int parEdgeU[MAXN];
int parEdgeV[MAXN];
void find_pair(int N, vector<int> U, vector<int> V, int A, int B) {
int M = U.size();
for(int i=0;i<M;i++)
{
g[U[i]].push_back({V[i],i});
g[V[i]].push_back({U[i],i});
}
vector<int>w;
w=vector<int>(M,0);
long long dist=(long long)ask(w);
long long low=0,high=M-1,best;
while(low<=high)
{
int mid=(low+high)/2;
for(int j=0;j<w.size();j++)w[j]=0;
for(int j=0;j<=mid;j++)
{
w[j]=1;
}
if(ask(w)==dist)
{
low=mid+1;
}
else
{
best=mid;
high=mid-1;
}
}
int u=U[best],v=V[best];
queue<int>bfsu,bfsv;
bfsu.push(u);
bfsv.push(v);
memset(distu,-1,sizeof(distu));
memset(distv,-1,sizeof(distv));
distu[u]=0;
parEdgeU[u]=-1;
distv[v]=0;
parEdgeV[v]=-1;
vector<pair<int,int> >tv,tu;
while(!bfsu.empty())
{
int t=bfsu.front();
bfsu.pop();
for(auto xd:g[t])
{
if(distu[xd.first]==-1)
{
distu[xd.first]=distu[t]+1;
parEdgeU[xd.first]=xd.second;
bfsu.push(xd.first);
}
}
}
while(!bfsv.empty())
{
int t=bfsv.front();
bfsv.pop();
for(auto xd:g[t])
{
if(distv[xd.first]==-1)
{
distv[xd.first]=distv[t]+1;
parEdgeV[xd.first]=xd.second;
bfsv.push(xd.first);
}
}
}
for(int i=0;i<N;i++)
{
if(distu[i]<distv[i])
{
tu.push_back({distu[i],i});
}
else
{
tv.push_back({distv[i],i});
}
}
sort(tu.begin(),tu.end());
sort(tv.begin(),tv.end());
low=0,high=tu.size()-1;
int s,t;
while(low<=high)
{
int mid=(low+high)/2;
for(int j=0;j<w.size();j++)w[j]=0;
w[best]=1;
for(int j=1;j<=mid;j++)
{
w[parEdgeU[tu[j].second]]=1;
}
for(int j=1;j<tv.size();j++)
{
w[parEdgeV[tv[j].second]]=1;
}
for(int j=0;j<w.size();j++)w[j]=1-w[j];
/*for(int j=0;j<w.size();j++)cout<<w[j]<<" ";
cout<<endl;
cout<<low<<" "<<high<<" "<<mid<<" "<<ask(w)<<endl;*/
if(ask(w)>(long long)dist)
{
low=mid+1;
}
else
{
s=tu[mid].second;
high=mid-1;
}
}
low=0;high=tv.size()-1;
//cout<<"dist: "<<dist<<" "<<dist*1ll/A*1ll*B<<endl;
while(low<=high)
{
int mid=(low+high)/2;
for(int j=0;j<w.size();j++)w[j]=0;
w[best]=1;
for(int j=1;j<=mid;j++)
{
w[parEdgeV[tv[j].second]]=1;
}
for(int j=1;j<tu.size();j++)
{
w[parEdgeU[tu[j].second]]=1;
}
for(int j=0;j<w.size();j++)w[j]=1-w[j];
/*for(int j=0;j<w.size();j++)cout<<w[j]<<" ";
cout<<endl;
cout<<low<<" "<<high<<" "<<mid<<" "<<ask(w)<<endl;*/
if(ask(w)>(long long)dist)
{
low=mid+1;
}
else
{
t=tv[mid].second;
high=mid-1;
}
}
/*cout<<"tu:\n";
for(auto xd:tu)cout<<xd.second<<" ";
cout<<endl;
cout<<"tv:\n";
for(auto xd:tv)cout<<xd.second<<" ";
cout<<endl;
cout<<s<<" "<<t<<endl;
cout<<s<<" "<<t<<endl;*/
answer(s,t);
}
Compilation message
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:24:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | for(int j=0;j<w.size();j++)w[j]=0;
| ~^~~~~~~~~
highway.cpp:96:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
96 | for(int j=0;j<w.size();j++)w[j]=0;
| ~^~~~~~~~~
highway.cpp:102:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
102 | for(int j=1;j<tv.size();j++)
| ~^~~~~~~~~~
highway.cpp:106:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
106 | for(int j=0;j<w.size();j++)w[j]=1-w[j];
| ~^~~~~~~~~
highway.cpp:125:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
125 | for(int j=0;j<w.size();j++)w[j]=0;
| ~^~~~~~~~~
highway.cpp:131:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
131 | for(int j=1;j<tu.size();j++)
| ~^~~~~~~~~~
highway.cpp:135:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
135 | for(int j=0;j<w.size();j++)w[j]=1-w[j];
| ~^~~~~~~~~
highway.cpp:158:11: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
158 | answer(s,t);
| ~~~~~~^~~~~
highway.cpp:158:11: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
highway.cpp:39:17: warning: 'best' may be used uninitialized in this function [-Wmaybe-uninitialized]
39 | int u=U[best],v=V[best];
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3024 KB |
Output is correct |
2 |
Correct |
3 ms |
3024 KB |
Output is correct |
3 |
Correct |
2 ms |
3024 KB |
Output is correct |
4 |
Correct |
2 ms |
3024 KB |
Output is correct |
5 |
Correct |
2 ms |
3024 KB |
Output is correct |
6 |
Correct |
2 ms |
3024 KB |
Output is correct |
7 |
Correct |
2 ms |
3068 KB |
Output is correct |
8 |
Correct |
2 ms |
3004 KB |
Output is correct |
9 |
Correct |
3 ms |
3024 KB |
Output is correct |
10 |
Correct |
2 ms |
3072 KB |
Output is correct |
11 |
Correct |
3 ms |
3024 KB |
Output is correct |
12 |
Correct |
2 ms |
3024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3152 KB |
Output is correct |
2 |
Correct |
16 ms |
3900 KB |
Output is correct |
3 |
Correct |
154 ms |
10148 KB |
Output is correct |
4 |
Correct |
128 ms |
10124 KB |
Output is correct |
5 |
Correct |
187 ms |
10112 KB |
Output is correct |
6 |
Correct |
151 ms |
10212 KB |
Output is correct |
7 |
Correct |
138 ms |
10116 KB |
Output is correct |
8 |
Correct |
157 ms |
10112 KB |
Output is correct |
9 |
Correct |
128 ms |
10156 KB |
Output is correct |
10 |
Correct |
175 ms |
10124 KB |
Output is correct |
11 |
Correct |
163 ms |
9488 KB |
Output is correct |
12 |
Correct |
166 ms |
9804 KB |
Output is correct |
13 |
Correct |
149 ms |
9552 KB |
Output is correct |
14 |
Correct |
152 ms |
9540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
3900 KB |
Output is correct |
2 |
Correct |
22 ms |
4564 KB |
Output is correct |
3 |
Correct |
37 ms |
5300 KB |
Output is correct |
4 |
Correct |
83 ms |
9412 KB |
Output is correct |
5 |
Correct |
100 ms |
9440 KB |
Output is correct |
6 |
Correct |
107 ms |
9700 KB |
Output is correct |
7 |
Correct |
110 ms |
9476 KB |
Output is correct |
8 |
Correct |
113 ms |
9232 KB |
Output is correct |
9 |
Correct |
94 ms |
9548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3120 KB |
Output is correct |
2 |
Correct |
15 ms |
3884 KB |
Output is correct |
3 |
Correct |
101 ms |
8776 KB |
Output is correct |
4 |
Correct |
145 ms |
10028 KB |
Output is correct |
5 |
Correct |
154 ms |
10028 KB |
Output is correct |
6 |
Correct |
164 ms |
10176 KB |
Output is correct |
7 |
Correct |
137 ms |
10048 KB |
Output is correct |
8 |
Correct |
127 ms |
10140 KB |
Output is correct |
9 |
Correct |
150 ms |
10216 KB |
Output is correct |
10 |
Correct |
162 ms |
10036 KB |
Output is correct |
11 |
Correct |
177 ms |
9556 KB |
Output is correct |
12 |
Correct |
154 ms |
9652 KB |
Output is correct |
13 |
Correct |
194 ms |
9788 KB |
Output is correct |
14 |
Correct |
164 ms |
9352 KB |
Output is correct |
15 |
Correct |
126 ms |
10120 KB |
Output is correct |
16 |
Correct |
109 ms |
10036 KB |
Output is correct |
17 |
Correct |
166 ms |
9548 KB |
Output is correct |
18 |
Correct |
190 ms |
9496 KB |
Output is correct |
19 |
Correct |
126 ms |
10144 KB |
Output is correct |
20 |
Correct |
129 ms |
9552 KB |
Output is correct |
21 |
Correct |
107 ms |
10980 KB |
Output is correct |
22 |
Correct |
154 ms |
10972 KB |
Output is correct |
23 |
Correct |
145 ms |
10384 KB |
Output is correct |
24 |
Correct |
163 ms |
10232 KB |
Output is correct |
25 |
Correct |
204 ms |
9656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
4004 KB |
Output is correct |
2 |
Correct |
18 ms |
4048 KB |
Output is correct |
3 |
Correct |
154 ms |
10484 KB |
Output is correct |
4 |
Correct |
240 ms |
10816 KB |
Output is correct |
5 |
Correct |
244 ms |
11820 KB |
Output is correct |
6 |
Correct |
249 ms |
11956 KB |
Output is correct |
7 |
Correct |
203 ms |
11920 KB |
Output is correct |
8 |
Correct |
226 ms |
11640 KB |
Output is correct |
9 |
Correct |
192 ms |
9320 KB |
Output is correct |
10 |
Correct |
136 ms |
9840 KB |
Output is correct |
11 |
Correct |
163 ms |
10276 KB |
Output is correct |
12 |
Correct |
176 ms |
11316 KB |
Output is correct |
13 |
Correct |
183 ms |
11496 KB |
Output is correct |
14 |
Correct |
261 ms |
11820 KB |
Output is correct |
15 |
Correct |
230 ms |
11720 KB |
Output is correct |
16 |
Correct |
161 ms |
10232 KB |
Output is correct |
17 |
Correct |
123 ms |
10524 KB |
Output is correct |
18 |
Correct |
130 ms |
10752 KB |
Output is correct |
19 |
Correct |
131 ms |
10664 KB |
Output is correct |
20 |
Correct |
123 ms |
10744 KB |
Output is correct |
21 |
Correct |
205 ms |
11972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
3924 KB |
Output is correct |
2 |
Correct |
19 ms |
3960 KB |
Output is correct |
3 |
Correct |
196 ms |
10348 KB |
Output is correct |
4 |
Correct |
169 ms |
10920 KB |
Output is correct |
5 |
Correct |
174 ms |
10992 KB |
Output is correct |
6 |
Correct |
226 ms |
11800 KB |
Output is correct |
7 |
Correct |
125 ms |
10484 KB |
Output is correct |
8 |
Correct |
183 ms |
10668 KB |
Output is correct |
9 |
Correct |
200 ms |
10780 KB |
Output is correct |
10 |
Correct |
224 ms |
12328 KB |
Output is correct |
11 |
Correct |
199 ms |
11848 KB |
Output is correct |
12 |
Correct |
183 ms |
11932 KB |
Output is correct |
13 |
Correct |
196 ms |
10196 KB |
Output is correct |
14 |
Correct |
121 ms |
9780 KB |
Output is correct |
15 |
Correct |
179 ms |
10224 KB |
Output is correct |
16 |
Correct |
119 ms |
9760 KB |
Output is correct |
17 |
Correct |
205 ms |
10252 KB |
Output is correct |
18 |
Correct |
129 ms |
9828 KB |
Output is correct |
19 |
Correct |
235 ms |
11228 KB |
Output is correct |
20 |
Correct |
231 ms |
11508 KB |
Output is correct |
21 |
Correct |
246 ms |
11768 KB |
Output is correct |
22 |
Correct |
201 ms |
11824 KB |
Output is correct |
23 |
Correct |
264 ms |
11728 KB |
Output is correct |
24 |
Correct |
192 ms |
11720 KB |
Output is correct |
25 |
Correct |
177 ms |
11908 KB |
Output is correct |
26 |
Correct |
262 ms |
11844 KB |
Output is correct |
27 |
Correct |
158 ms |
10696 KB |
Output is correct |
28 |
Correct |
151 ms |
10576 KB |
Output is correct |
29 |
Correct |
156 ms |
10840 KB |
Output is correct |
30 |
Correct |
137 ms |
10708 KB |
Output is correct |
31 |
Correct |
109 ms |
10564 KB |
Output is correct |
32 |
Correct |
119 ms |
10596 KB |
Output is correct |
33 |
Correct |
133 ms |
10820 KB |
Output is correct |
34 |
Correct |
119 ms |
10568 KB |
Output is correct |
35 |
Correct |
112 ms |
10564 KB |
Output is correct |
36 |
Correct |
117 ms |
10528 KB |
Output is correct |
37 |
Correct |
160 ms |
10708 KB |
Output is correct |
38 |
Correct |
106 ms |
10700 KB |
Output is correct |
39 |
Correct |
243 ms |
11968 KB |
Output is correct |
40 |
Correct |
193 ms |
11964 KB |
Output is correct |
41 |
Correct |
190 ms |
11904 KB |
Output is correct |
42 |
Correct |
196 ms |
11680 KB |
Output is correct |