// moreflags=grader.cpp
// :(
#include "highway.h"
#if not LOCAL
#define NDEBUG
#endif
#include<cassert>
#include<vector>
#include<cstdint>
#include<algorithm>
void find_pair(int number, std::vector<int> U, std::vector<int> V, int A, int B) {
std::vector<int> query(U.size(), 0);
auto const d1=ask(query); // a*(distance from S to T)
int i=0;
for(int step=1<<20; step>>=1;) if(i+step<(int)U.size()){
query.assign(i+step, 1); query.resize(U.size(), 0);
auto const d=ask(query);
if(d==d1) i+=step;
}
// now i is the maximum value such that there's a shortest path not passing through the first i edges
// therefore there must be a shortest path passing through edge [i]
struct Edge{int node, index;};
std::array<std::vector<Edge>, 2> edges; // edge indices in the bfs tree, split by sourceIndex,
// each one is ordered by distance from source node
// (node in each edge struct is the node farther from the corresponding source node)
std::array<int, 2> source{{U[i], V[i]}};
{
// construct adjacency list
std::vector<std::vector<Edge>> add(number);
for(int index=0; index<(int)U.size(); ++index){
auto const a=U[index], b=V[index];
add[a].push_back({b, index}); add[b].push_back({a, index});
}
// multisource bfs from edge [i]
struct Item{int node, sourceIndex;};
std::vector<Item> queue; queue.reserve(number);
std::vector<char> visited(number);
for(int i=0; i<2; ++i){
queue.push_back({source[i], i}); visited[source[i]]=true;
}
for(int start=0; start<(int)queue.size(); ++start){
auto const [node, sourceIndex]=queue[start];
for(auto [other, edgeIndex]: add[node]) if(not visited[other]){
edges[sourceIndex].push_back({other, edgeIndex});
visited[other]=true;
queue.push_back({other, sourceIndex});
}
}
}
std::array<int, 2> result;
for(int sourceIndex=0; sourceIndex<2; ++sourceIndex){
int j=(int)edges[sourceIndex].size();
for(int step=1<<20; step>>=1;) if(j-step>=0){
query.assign(U.size(), 1);
query[i]=0;
for(auto [other, index]: edges[not sourceIndex]) query[index]=0;
for(int k=0; k<j-step; ++k) query[edges[sourceIndex][k].index]=0;
if(ask(query)==d1) j-=step;
}
// now j is the smallest value such that the sourceIndex half of the shortest path
// is included in the first j nodes of edges[sourceIndex]
result[sourceIndex]=j==0 ? source[sourceIndex]: edges[sourceIndex][j-1].node;
}
answer(result[0], result[1]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
372 KB |
Output is correct |
3 |
Correct |
1 ms |
360 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
368 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
14 ms |
1408 KB |
Output is correct |
3 |
Correct |
164 ms |
9300 KB |
Output is correct |
4 |
Correct |
167 ms |
9300 KB |
Output is correct |
5 |
Correct |
155 ms |
9304 KB |
Output is correct |
6 |
Correct |
143 ms |
9300 KB |
Output is correct |
7 |
Correct |
161 ms |
9304 KB |
Output is correct |
8 |
Correct |
149 ms |
9352 KB |
Output is correct |
9 |
Correct |
153 ms |
9428 KB |
Output is correct |
10 |
Correct |
158 ms |
9372 KB |
Output is correct |
11 |
Correct |
165 ms |
8792 KB |
Output is correct |
12 |
Correct |
160 ms |
9080 KB |
Output is correct |
13 |
Correct |
173 ms |
8904 KB |
Output is correct |
14 |
Correct |
161 ms |
9044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
1400 KB |
Output is correct |
2 |
Correct |
19 ms |
2304 KB |
Output is correct |
3 |
Correct |
39 ms |
3136 KB |
Output is correct |
4 |
Correct |
117 ms |
8676 KB |
Output is correct |
5 |
Correct |
122 ms |
8816 KB |
Output is correct |
6 |
Correct |
121 ms |
9124 KB |
Output is correct |
7 |
Correct |
102 ms |
8916 KB |
Output is correct |
8 |
Correct |
125 ms |
8736 KB |
Output is correct |
9 |
Correct |
118 ms |
9196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
15 ms |
1408 KB |
Output is correct |
3 |
Correct |
110 ms |
7760 KB |
Output is correct |
4 |
Correct |
176 ms |
9300 KB |
Output is correct |
5 |
Correct |
155 ms |
9284 KB |
Output is correct |
6 |
Correct |
134 ms |
9260 KB |
Output is correct |
7 |
Correct |
150 ms |
9308 KB |
Output is correct |
8 |
Correct |
131 ms |
9292 KB |
Output is correct |
9 |
Correct |
159 ms |
9412 KB |
Output is correct |
10 |
Correct |
180 ms |
9420 KB |
Output is correct |
11 |
Correct |
172 ms |
8816 KB |
Output is correct |
12 |
Correct |
152 ms |
8936 KB |
Output is correct |
13 |
Correct |
169 ms |
9164 KB |
Output is correct |
14 |
Correct |
172 ms |
8604 KB |
Output is correct |
15 |
Correct |
147 ms |
9300 KB |
Output is correct |
16 |
Correct |
143 ms |
9288 KB |
Output is correct |
17 |
Correct |
167 ms |
8988 KB |
Output is correct |
18 |
Correct |
164 ms |
8824 KB |
Output is correct |
19 |
Correct |
140 ms |
9372 KB |
Output is correct |
20 |
Correct |
173 ms |
9040 KB |
Output is correct |
21 |
Correct |
130 ms |
9912 KB |
Output is correct |
22 |
Correct |
128 ms |
9884 KB |
Output is correct |
23 |
Correct |
143 ms |
9552 KB |
Output is correct |
24 |
Correct |
136 ms |
9612 KB |
Output is correct |
25 |
Correct |
159 ms |
9048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
1400 KB |
Output is correct |
2 |
Correct |
16 ms |
1528 KB |
Output is correct |
3 |
Correct |
176 ms |
9684 KB |
Output is correct |
4 |
Correct |
192 ms |
10524 KB |
Output is correct |
5 |
Correct |
214 ms |
11472 KB |
Output is correct |
6 |
Correct |
219 ms |
10892 KB |
Output is correct |
7 |
Correct |
222 ms |
10976 KB |
Output is correct |
8 |
Correct |
216 ms |
10972 KB |
Output is correct |
9 |
Correct |
168 ms |
7168 KB |
Output is correct |
10 |
Correct |
174 ms |
7516 KB |
Output is correct |
11 |
Correct |
177 ms |
8256 KB |
Output is correct |
12 |
Correct |
214 ms |
10048 KB |
Output is correct |
13 |
Correct |
232 ms |
10440 KB |
Output is correct |
14 |
Correct |
237 ms |
10968 KB |
Output is correct |
15 |
Correct |
227 ms |
11248 KB |
Output is correct |
16 |
Correct |
204 ms |
8356 KB |
Output is correct |
17 |
Correct |
154 ms |
9760 KB |
Output is correct |
18 |
Correct |
153 ms |
9884 KB |
Output is correct |
19 |
Correct |
153 ms |
9724 KB |
Output is correct |
20 |
Correct |
143 ms |
9748 KB |
Output is correct |
21 |
Correct |
261 ms |
11360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
1408 KB |
Output is correct |
2 |
Correct |
18 ms |
1528 KB |
Output is correct |
3 |
Correct |
177 ms |
9516 KB |
Output is correct |
4 |
Correct |
179 ms |
9804 KB |
Output is correct |
5 |
Correct |
204 ms |
10080 KB |
Output is correct |
6 |
Correct |
207 ms |
10916 KB |
Output is correct |
7 |
Correct |
172 ms |
9720 KB |
Output is correct |
8 |
Correct |
189 ms |
10004 KB |
Output is correct |
9 |
Correct |
196 ms |
9972 KB |
Output is correct |
10 |
Correct |
234 ms |
10948 KB |
Output is correct |
11 |
Correct |
215 ms |
11256 KB |
Output is correct |
12 |
Correct |
221 ms |
10860 KB |
Output is correct |
13 |
Correct |
173 ms |
8268 KB |
Output is correct |
14 |
Correct |
156 ms |
7456 KB |
Output is correct |
15 |
Correct |
163 ms |
8336 KB |
Output is correct |
16 |
Correct |
163 ms |
7412 KB |
Output is correct |
17 |
Correct |
179 ms |
8312 KB |
Output is correct |
18 |
Correct |
185 ms |
7492 KB |
Output is correct |
19 |
Correct |
210 ms |
10076 KB |
Output is correct |
20 |
Correct |
230 ms |
11144 KB |
Output is correct |
21 |
Correct |
225 ms |
10936 KB |
Output is correct |
22 |
Correct |
249 ms |
10896 KB |
Output is correct |
23 |
Correct |
237 ms |
11004 KB |
Output is correct |
24 |
Correct |
236 ms |
10924 KB |
Output is correct |
25 |
Correct |
233 ms |
11556 KB |
Output is correct |
26 |
Correct |
219 ms |
11476 KB |
Output is correct |
27 |
Correct |
141 ms |
9888 KB |
Output is correct |
28 |
Correct |
146 ms |
9720 KB |
Output is correct |
29 |
Correct |
132 ms |
9992 KB |
Output is correct |
30 |
Correct |
145 ms |
9844 KB |
Output is correct |
31 |
Correct |
137 ms |
9780 KB |
Output is correct |
32 |
Correct |
153 ms |
9728 KB |
Output is correct |
33 |
Correct |
150 ms |
9976 KB |
Output is correct |
34 |
Correct |
133 ms |
9796 KB |
Output is correct |
35 |
Correct |
139 ms |
9872 KB |
Output is correct |
36 |
Correct |
139 ms |
9592 KB |
Output is correct |
37 |
Correct |
144 ms |
9884 KB |
Output is correct |
38 |
Correct |
139 ms |
9812 KB |
Output is correct |
39 |
Correct |
227 ms |
11452 KB |
Output is correct |
40 |
Correct |
250 ms |
11404 KB |
Output is correct |
41 |
Correct |
259 ms |
11108 KB |
Output is correct |
42 |
Correct |
240 ms |
11124 KB |
Output is correct |