#include "highway.h"
#include <queue>
#include <stdint.h>
#include <cstdio>
#include <algorithm>
static const int INF=1e9+7;
static void dfs(int node,int parent,const std::vector<int>& elist,const std::vector<std::vector<int> >& adj,
std::vector<int>& post){
for(int e:adj[node]){
int child=elist[e^1];
if(child==parent) continue;
dfs(child,node,elist,adj,post);
post.push_back(e^1);
}
}
static int find_first_vertex(const std::vector<int>& elist,const std::vector<std::vector<int> >& adj,int64_t base,const std::vector<int>& mask,int root){
std::vector<int> post;
dfs(root,root,elist,adj,post);
/*
printf("postorder:\n");
for(int i=0;i<post.size();i++){
printf(" %d=>%d\n",elist[post[i]],elist[post[i]^1]);
}
*/
int low=0,high=post.size();
while(high-low>1){
int mid=(low+high)/2;
std::vector<int> ws(mask);
for(int i=0;i<mid;i++){
ws[post[i]>>1]=1;
}
if(ask(ws)>base){
high=mid;
}else{
low=mid;
}
}
//printf("critical tree edge: %d=>%d\n",elist[post[low]],elist[post[low]^1]);
return elist[post[low]];
}
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
int M = U.size();
int64_t base=ask(std::vector<int>(M));
//printf("BASE=%ld\n",base);
std::vector<int> elist;
std::vector<std::vector<int> > adj(N);
for(int i=0;i<M;i++){
elist.push_back(U[i]);
elist.push_back(V[i]);
adj[U[i]].push_back(i*2);
adj[V[i]].push_back(i*2+1);
}
int low=0,high=M;
while(high-low>1){
int mid=(low+high)/2;
std::vector<int> ws(M);
for(int i=0;i<mid;i++){
ws[i]=1;
}
if(ask(ws)>base){
high=mid;
}else{
low=mid;
}
}
//printf("critical: %d<=>%d\n",U[low],V[low]);
std::vector<int> from(N);
std::queue<int> frontier;
std::vector<int> dist(N,INF);
dist[U[low]]=0;
frontier.push(U[low]);
dist[V[low]]=0;
frontier.push(V[low]);
while(!frontier.empty()){
int node=frontier.front();
frontier.pop();
for(int e:adj[node]){
if((e>>1)<low) continue;
int child=elist[e^1];
if(dist[child]==INF){
dist[child]=dist[node]+1;
from[child]=e;
frontier.push(child);
}
}
}
std::vector<int> ws(M,1);
adj.clear();
adj.resize(N);
for(int i=0;i<N;i++){
if(dist[i]!=0&&dist[i]!=INF){
int e=from[i];
int U=elist[e];
int V=elist[e^1];
adj[U].push_back(e);
adj[V].push_back(e^1);
ws[e>>1]=0;
}
}
adj[U[low]].push_back(low*2);
adj[V[low]].push_back(low*2+1);
ws[low]=0;
int S=find_first_vertex(elist,adj,base,ws,U[low]);
int T=find_first_vertex(elist,adj,base,ws,S);
//printf("S=%d, T=%d\n",S,T);
answer(S,T);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
312 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
248 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
292 KB |
Output is correct |
6 |
Correct |
2 ms |
248 KB |
Output is correct |
7 |
Correct |
2 ms |
248 KB |
Output is correct |
8 |
Correct |
2 ms |
248 KB |
Output is correct |
9 |
Correct |
2 ms |
248 KB |
Output is correct |
10 |
Correct |
2 ms |
248 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
420 KB |
Output is correct |
2 |
Correct |
27 ms |
1320 KB |
Output is correct |
3 |
Correct |
229 ms |
9356 KB |
Output is correct |
4 |
Correct |
241 ms |
9344 KB |
Output is correct |
5 |
Correct |
256 ms |
9464 KB |
Output is correct |
6 |
Correct |
238 ms |
9356 KB |
Output is correct |
7 |
Correct |
214 ms |
9364 KB |
Output is correct |
8 |
Correct |
239 ms |
9432 KB |
Output is correct |
9 |
Correct |
215 ms |
9328 KB |
Output is correct |
10 |
Correct |
259 ms |
9420 KB |
Output is correct |
11 |
Correct |
212 ms |
9592 KB |
Output is correct |
12 |
Correct |
276 ms |
11720 KB |
Output is correct |
13 |
Correct |
279 ms |
11528 KB |
Output is correct |
14 |
Correct |
286 ms |
11516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
2100 KB |
Output is correct |
2 |
Correct |
48 ms |
3652 KB |
Output is correct |
3 |
Correct |
53 ms |
3364 KB |
Output is correct |
4 |
Correct |
226 ms |
13728 KB |
Output is correct |
5 |
Correct |
184 ms |
13752 KB |
Output is correct |
6 |
Correct |
186 ms |
15780 KB |
Output is correct |
7 |
Correct |
172 ms |
8860 KB |
Output is correct |
8 |
Correct |
189 ms |
14828 KB |
Output is correct |
9 |
Correct |
183 ms |
10612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
48 ms |
1276 KB |
Output is correct |
3 |
Correct |
182 ms |
7512 KB |
Output is correct |
4 |
Correct |
241 ms |
9316 KB |
Output is correct |
5 |
Correct |
206 ms |
8880 KB |
Output is correct |
6 |
Correct |
185 ms |
8896 KB |
Output is correct |
7 |
Correct |
229 ms |
9316 KB |
Output is correct |
8 |
Correct |
175 ms |
8964 KB |
Output is correct |
9 |
Correct |
230 ms |
9360 KB |
Output is correct |
10 |
Correct |
233 ms |
9388 KB |
Output is correct |
11 |
Correct |
293 ms |
11128 KB |
Output is correct |
12 |
Correct |
270 ms |
12460 KB |
Output is correct |
13 |
Correct |
258 ms |
11448 KB |
Output is correct |
14 |
Correct |
223 ms |
10028 KB |
Output is correct |
15 |
Correct |
183 ms |
8916 KB |
Output is correct |
16 |
Correct |
185 ms |
8652 KB |
Output is correct |
17 |
Correct |
274 ms |
11152 KB |
Output is correct |
18 |
Correct |
254 ms |
12140 KB |
Output is correct |
19 |
Correct |
188 ms |
9004 KB |
Output is correct |
20 |
Correct |
211 ms |
8988 KB |
Output is correct |
21 |
Correct |
201 ms |
9592 KB |
Output is correct |
22 |
Correct |
182 ms |
9248 KB |
Output is correct |
23 |
Correct |
188 ms |
10340 KB |
Output is correct |
24 |
Correct |
200 ms |
10736 KB |
Output is correct |
25 |
Correct |
297 ms |
16892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
1332 KB |
Output is correct |
2 |
Correct |
17 ms |
1312 KB |
Output is correct |
3 |
Correct |
259 ms |
9752 KB |
Output is correct |
4 |
Correct |
304 ms |
10016 KB |
Output is correct |
5 |
Correct |
334 ms |
11160 KB |
Output is correct |
6 |
Correct |
354 ms |
10924 KB |
Output is correct |
7 |
Correct |
348 ms |
10784 KB |
Output is correct |
8 |
Correct |
365 ms |
11180 KB |
Output is correct |
9 |
Correct |
194 ms |
6608 KB |
Output is correct |
10 |
Correct |
269 ms |
7332 KB |
Output is correct |
11 |
Correct |
268 ms |
7952 KB |
Output is correct |
12 |
Correct |
311 ms |
9992 KB |
Output is correct |
13 |
Correct |
319 ms |
10452 KB |
Output is correct |
14 |
Correct |
364 ms |
10632 KB |
Output is correct |
15 |
Correct |
354 ms |
11140 KB |
Output is correct |
16 |
Correct |
285 ms |
8524 KB |
Output is correct |
17 |
Correct |
207 ms |
9800 KB |
Output is correct |
18 |
Correct |
171 ms |
9132 KB |
Output is correct |
19 |
Correct |
230 ms |
10116 KB |
Output is correct |
20 |
Correct |
216 ms |
9652 KB |
Output is correct |
21 |
Correct |
359 ms |
11376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
1328 KB |
Output is correct |
2 |
Correct |
25 ms |
1364 KB |
Output is correct |
3 |
Correct |
283 ms |
9808 KB |
Output is correct |
4 |
Correct |
271 ms |
9868 KB |
Output is correct |
5 |
Partially correct |
298 ms |
10092 KB |
Output is partially correct |
6 |
Partially correct |
350 ms |
10772 KB |
Output is partially correct |
7 |
Correct |
287 ms |
9788 KB |
Output is correct |
8 |
Partially correct |
291 ms |
9960 KB |
Output is partially correct |
9 |
Partially correct |
297 ms |
10024 KB |
Output is partially correct |
10 |
Partially correct |
354 ms |
10856 KB |
Output is partially correct |
11 |
Partially correct |
334 ms |
10916 KB |
Output is partially correct |
12 |
Partially correct |
325 ms |
10808 KB |
Output is partially correct |
13 |
Correct |
246 ms |
7600 KB |
Output is correct |
14 |
Correct |
256 ms |
6796 KB |
Output is correct |
15 |
Correct |
231 ms |
8024 KB |
Output is correct |
16 |
Correct |
259 ms |
7316 KB |
Output is correct |
17 |
Correct |
265 ms |
7968 KB |
Output is correct |
18 |
Correct |
253 ms |
7448 KB |
Output is correct |
19 |
Correct |
327 ms |
9872 KB |
Output is correct |
20 |
Partially correct |
331 ms |
10240 KB |
Output is partially correct |
21 |
Partially correct |
360 ms |
10720 KB |
Output is partially correct |
22 |
Partially correct |
366 ms |
11108 KB |
Output is partially correct |
23 |
Correct |
355 ms |
11136 KB |
Output is correct |
24 |
Partially correct |
355 ms |
11152 KB |
Output is partially correct |
25 |
Correct |
369 ms |
11064 KB |
Output is correct |
26 |
Partially correct |
345 ms |
11168 KB |
Output is partially correct |
27 |
Correct |
178 ms |
9536 KB |
Output is correct |
28 |
Correct |
215 ms |
10032 KB |
Output is correct |
29 |
Correct |
238 ms |
10508 KB |
Output is correct |
30 |
Correct |
207 ms |
10264 KB |
Output is correct |
31 |
Correct |
220 ms |
10056 KB |
Output is correct |
32 |
Correct |
192 ms |
10016 KB |
Output is correct |
33 |
Partially correct |
223 ms |
10096 KB |
Output is partially correct |
34 |
Correct |
217 ms |
9832 KB |
Output is correct |
35 |
Correct |
228 ms |
9884 KB |
Output is correct |
36 |
Partially correct |
231 ms |
10080 KB |
Output is partially correct |
37 |
Correct |
212 ms |
10260 KB |
Output is correct |
38 |
Correct |
244 ms |
10032 KB |
Output is correct |
39 |
Partially correct |
365 ms |
12108 KB |
Output is partially correct |
40 |
Partially correct |
367 ms |
12056 KB |
Output is partially correct |
41 |
Partially correct |
350 ms |
11204 KB |
Output is partially correct |
42 |
Correct |
341 ms |
11108 KB |
Output is correct |