#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[90000];
int dist1[90000], dist2[90000];
bool chk[90000];
void find_pair(int N, vector<int> U, vector<int> V, int A, int B)
{
int M=U.size(), S, T, s, e, E;
vector<int> W(M,0), C1, C2;
queue<int> Q;
long long D=ask(W);
for(int i=0;i<M;i++) {
adj[U[i]].push_back(V[i]);
adj[V[i]].push_back(U[i]);
}
s=0; e=N-1;
while(s<=e) {
int m=(s+e)>>1;
for(int i=0;i<N;i++) W[i]=i<=m;
if(ask(W)!=D) e=m-1;
else s=m+1;
}
E=s;
memset(dist1,0x7f,sizeof(dist1));
memset(dist2,0x7f,sizeof(dist2));
dist1[U[E]]=0; Q.push(U[E]);
while(!Q.empty()) {
int c=Q.front();
Q.pop();
for(auto n: adj[c]) if(dist1[n]>dist1[c]+1) {
dist1[n]=dist1[c]+1;
Q.push(n);
}
}
dist2[V[E]]=0; Q.push(V[E]);
while(!Q.empty()) {
int c=Q.front();
Q.pop();
for(auto n: adj[c]) if(dist2[n]>dist2[c]+1) {
dist2[n]=dist2[c]+1;
Q.push(n);
}
}
s=0; e=D/A-1;
while(s<=e) {
int m=(s+e)>>1;
for(int i=0;i<M;i++) W[i]=(dist1[U[i]]<dist2[U[i]] || dist1[U[i]]==0 && dist2[V[i]]==0) && dist1[U[i]]>=m || (dist1[V[i]]<dist2[V[i]] || dist1[V[i]]==0 && dist2[U[i]]==0) && dist1[V[i]]>=m;
if(ask(W)!=D) s=m+1;
else e=m-1;
}
for(int i=0;i<N;i++) {
if(dist1[i]<dist2[i] && dist1[i]==e) C1.push_back(i);
if(dist1[i]>dist2[i] && dist2[i]==D/A-s) C2.push_back(i);
chk[i]=false;
}
s=0; e=C1.size()-1;
while(s<=e) {
int m=(s+e)>>1;
for(int i=0;i<N;i++) chk[i]=false;
for(int i=0;i<=m;i++) chk[C1[i]]=true;
for(int i=0;i<M;i++) W[i]=chk[U[i]] || chk[V[i]];
if(ask(W)!=D) e=m-1;
else s=m+1;
}
S=C1[s];
s=0; e=C2.size()-1;
while(s<=e) {
int m=(s+e)>>1;
for(int i=0;i<N;i++) chk[i]=false;
for(int i=0;i<=m;i++) chk[C2[i]]=true;
for(int i=0;i<M;i++) W[i]=chk[U[i]] || chk[V[i]];
if(ask(W)!=D) e=m-1;
else s=m+1;
}
T=C2[s];
answer(S,T);
}
Compilation message
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:51:72: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
for(int i=0;i<M;i++) W[i]=(dist1[U[i]]<dist2[U[i]] || dist1[U[i]]==0 && dist2[V[i]]==0) && dist1[U[i]]>=m || (dist1[V[i]]<dist2[V[i]] || dist1[V[i]]==0 && dist2[U[i]]==0) && dist1[V[i]]>=m;
~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
highway.cpp:51:155: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
for(int i=0;i<M;i++) W[i]=(dist1[U[i]]<dist2[U[i]] || dist1[U[i]]==0 && dist2[V[i]]==0) && dist1[U[i]]>=m || (dist1[V[i]]<dist2[V[i]] || dist1[V[i]]==0 && dist2[U[i]]==0) && dist1[V[i]]>=m;
~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
highway.cpp:51:91: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
for(int i=0;i<M;i++) W[i]=(dist1[U[i]]<dist2[U[i]] || dist1[U[i]]==0 && dist2[V[i]]==0) && dist1[U[i]]>=m || (dist1[V[i]]<dist2[V[i]] || dist1[V[i]]==0 && dist2[U[i]]==0) && dist1[V[i]]>=m;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
3080 KB |
Output is correct |
2 |
Correct |
4 ms |
3164 KB |
Output is correct |
3 |
Runtime error |
11 ms |
6312 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
3192 KB |
Output is correct |
2 |
Correct |
25 ms |
3576 KB |
Output is correct |
3 |
Correct |
194 ms |
8032 KB |
Output is correct |
4 |
Correct |
207 ms |
8084 KB |
Output is correct |
5 |
Correct |
212 ms |
8060 KB |
Output is correct |
6 |
Correct |
203 ms |
7956 KB |
Output is correct |
7 |
Correct |
209 ms |
8144 KB |
Output is correct |
8 |
Correct |
187 ms |
7968 KB |
Output is correct |
9 |
Correct |
194 ms |
8052 KB |
Output is correct |
10 |
Correct |
202 ms |
8040 KB |
Output is correct |
11 |
Correct |
216 ms |
7752 KB |
Output is correct |
12 |
Correct |
240 ms |
7816 KB |
Output is correct |
13 |
Correct |
216 ms |
7736 KB |
Output is correct |
14 |
Correct |
202 ms |
7736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
3704 KB |
Output is correct |
2 |
Correct |
41 ms |
4092 KB |
Output is correct |
3 |
Correct |
52 ms |
4652 KB |
Output is correct |
4 |
Correct |
141 ms |
7736 KB |
Output is correct |
5 |
Correct |
157 ms |
7732 KB |
Output is correct |
6 |
Correct |
165 ms |
7764 KB |
Output is correct |
7 |
Correct |
161 ms |
7736 KB |
Output is correct |
8 |
Correct |
169 ms |
7736 KB |
Output is correct |
9 |
Correct |
155 ms |
7776 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
3192 KB |
Output is correct |
2 |
Correct |
25 ms |
3576 KB |
Output is correct |
3 |
Correct |
136 ms |
6820 KB |
Output is correct |
4 |
Correct |
200 ms |
8028 KB |
Output is correct |
5 |
Correct |
182 ms |
7888 KB |
Output is correct |
6 |
Correct |
198 ms |
7872 KB |
Output is correct |
7 |
Correct |
197 ms |
7892 KB |
Output is correct |
8 |
Correct |
199 ms |
7868 KB |
Output is correct |
9 |
Correct |
219 ms |
8056 KB |
Output is correct |
10 |
Correct |
190 ms |
8072 KB |
Output is correct |
11 |
Correct |
204 ms |
7748 KB |
Output is correct |
12 |
Correct |
212 ms |
7816 KB |
Output is correct |
13 |
Correct |
244 ms |
7916 KB |
Output is correct |
14 |
Correct |
211 ms |
7732 KB |
Output is correct |
15 |
Correct |
203 ms |
7944 KB |
Output is correct |
16 |
Correct |
179 ms |
7980 KB |
Output is correct |
17 |
Correct |
226 ms |
7780 KB |
Output is correct |
18 |
Correct |
199 ms |
7896 KB |
Output is correct |
19 |
Correct |
182 ms |
8024 KB |
Output is correct |
20 |
Correct |
203 ms |
7816 KB |
Output is correct |
21 |
Correct |
194 ms |
9276 KB |
Output is correct |
22 |
Correct |
204 ms |
9156 KB |
Output is correct |
23 |
Correct |
216 ms |
9200 KB |
Output is correct |
24 |
Correct |
254 ms |
8840 KB |
Output is correct |
25 |
Correct |
235 ms |
8056 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
3700 KB |
Output is correct |
2 |
Correct |
27 ms |
3744 KB |
Output is correct |
3 |
Correct |
226 ms |
8436 KB |
Output is correct |
4 |
Correct |
249 ms |
8536 KB |
Output is correct |
5 |
Correct |
258 ms |
9096 KB |
Output is correct |
6 |
Correct |
268 ms |
9024 KB |
Output is correct |
7 |
Correct |
307 ms |
8988 KB |
Output is correct |
8 |
Correct |
261 ms |
8980 KB |
Output is correct |
9 |
Runtime error |
218 ms |
14872 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
3692 KB |
Output is correct |
2 |
Correct |
27 ms |
3752 KB |
Output is correct |
3 |
Correct |
224 ms |
8208 KB |
Output is correct |
4 |
Correct |
230 ms |
8352 KB |
Output is correct |
5 |
Correct |
231 ms |
8504 KB |
Output is correct |
6 |
Correct |
286 ms |
9124 KB |
Output is correct |
7 |
Correct |
209 ms |
8300 KB |
Output is correct |
8 |
Correct |
221 ms |
8432 KB |
Output is correct |
9 |
Correct |
241 ms |
8548 KB |
Output is correct |
10 |
Correct |
265 ms |
8988 KB |
Output is correct |
11 |
Correct |
279 ms |
9008 KB |
Output is correct |
12 |
Correct |
291 ms |
9064 KB |
Output is correct |
13 |
Runtime error |
231 ms |
15552 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
14 |
Halted |
0 ms |
0 KB |
- |