#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 90000;
const int MAX_M = 130000;
struct Edge {
int a, b;
int other(int x) {
return a ^ b ^ x;
}
} edge[MAX_M];
vector<int> graph[MAX_N];
vector<pair<int, int> > tree[2];
bool viz[MAX_N];
void buildSmallTrees(int eid, const std::vector<int> &U,
const std::vector<int> &V) {
int X, Y;
for(int i = 0; i < U.size(); ++i) {
edge[i] = {U[i], V[i]};
graph[U[i]].push_back(i);
graph[V[i]].push_back(i);
}
X = edge[eid].a, Y = edge[eid].b;
deque<pair<int, int> > q;
q.push_back(make_pair(X, 0));
q.push_back(make_pair(Y, 1));
tree[0].push_back(make_pair(X, eid));
tree[1].push_back(make_pair(Y, eid));
viz[X] = viz[Y] = true;
while(!q.empty()) {
int nod, t;
nod = q.front().first;
t = q.front().second;
q.pop_front();
for(auto it: graph[nod]) {
int son = edge[it].other(nod);
if(!viz[son]) {
viz[son] = true;
tree[t].push_back(make_pair(son, it));
q.push_back(make_pair(son, t));
}
}
}
}
int searchTree(int t, int M, long long refpath) {
int st = -1, dr = tree[t].size();
vector<int> w(M, 0);
reverse(tree[t].begin(), tree[t].end());
while(dr - st > 1) {
int mid = (st + dr) / 2;
for(int i = 0; i < M; ++i)
w[i] = 1;
for(int i = 0; i < 2; ++i)
for(auto it: tree[i])
w[it.second] = 0;
for(int i = 0; i <= mid; ++i)
w[tree[t][i].second] = 1;
if(ask(w) > refpath)
dr = mid;
else
st = mid;
}
return tree[t][dr].first;
}
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
int M = U.size();
int st, dr;
long long refPath;
vector<int> w(M, 0);
refPath = ask(w);
st = -1, dr = M;
while(dr - st > 1) {
int mid = (st + dr) / 2;
for(int i = 0; i <= mid; ++i)
w[i] = 1;
for(int i = mid + 1; i < M; ++i)
w[i] = 0;
if(ask(w) > refPath)
dr = mid;
else
st = mid;
}
// Muchia (U[dr], V[dr]) face parte dintr-un drum sigur
buildSmallTrees(dr, U, V);
answer(searchTree(0, M, refPath), searchTree(1, M, refPath));
}
Compilation message
highway.cpp: In function 'void buildSmallTrees(int, const std::vector<int>&, const std::vector<int>&)':
highway.cpp:23:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < U.size(); ++i) {
~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2528 KB |
Output is correct |
2 |
Correct |
5 ms |
2424 KB |
Output is correct |
3 |
Correct |
4 ms |
2424 KB |
Output is correct |
4 |
Correct |
4 ms |
2344 KB |
Output is correct |
5 |
Correct |
4 ms |
2504 KB |
Output is correct |
6 |
Correct |
4 ms |
2424 KB |
Output is correct |
7 |
Correct |
4 ms |
2444 KB |
Output is correct |
8 |
Correct |
4 ms |
2344 KB |
Output is correct |
9 |
Correct |
4 ms |
2552 KB |
Output is correct |
10 |
Correct |
4 ms |
2424 KB |
Output is correct |
11 |
Correct |
4 ms |
2424 KB |
Output is correct |
12 |
Correct |
4 ms |
2552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2552 KB |
Output is correct |
2 |
Correct |
24 ms |
3148 KB |
Output is correct |
3 |
Correct |
208 ms |
9076 KB |
Output is correct |
4 |
Correct |
221 ms |
9080 KB |
Output is correct |
5 |
Correct |
211 ms |
9080 KB |
Output is correct |
6 |
Correct |
200 ms |
9068 KB |
Output is correct |
7 |
Correct |
214 ms |
9152 KB |
Output is correct |
8 |
Correct |
186 ms |
9132 KB |
Output is correct |
9 |
Correct |
205 ms |
9152 KB |
Output is correct |
10 |
Correct |
199 ms |
9088 KB |
Output is correct |
11 |
Correct |
221 ms |
9112 KB |
Output is correct |
12 |
Correct |
219 ms |
9040 KB |
Output is correct |
13 |
Correct |
211 ms |
8956 KB |
Output is correct |
14 |
Correct |
208 ms |
9076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
3152 KB |
Output is correct |
2 |
Correct |
40 ms |
3964 KB |
Output is correct |
3 |
Correct |
62 ms |
4704 KB |
Output is correct |
4 |
Correct |
181 ms |
9016 KB |
Output is correct |
5 |
Correct |
182 ms |
9080 KB |
Output is correct |
6 |
Correct |
189 ms |
9112 KB |
Output is correct |
7 |
Correct |
175 ms |
8948 KB |
Output is correct |
8 |
Correct |
181 ms |
9008 KB |
Output is correct |
9 |
Correct |
190 ms |
9076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
2552 KB |
Output is correct |
2 |
Correct |
23 ms |
3208 KB |
Output is correct |
3 |
Correct |
138 ms |
7788 KB |
Output is correct |
4 |
Correct |
192 ms |
9080 KB |
Output is correct |
5 |
Correct |
203 ms |
8980 KB |
Output is correct |
6 |
Correct |
189 ms |
9144 KB |
Output is correct |
7 |
Correct |
205 ms |
8992 KB |
Output is correct |
8 |
Correct |
155 ms |
9072 KB |
Output is correct |
9 |
Correct |
204 ms |
9072 KB |
Output is correct |
10 |
Correct |
223 ms |
9184 KB |
Output is correct |
11 |
Correct |
223 ms |
8980 KB |
Output is correct |
12 |
Correct |
208 ms |
8992 KB |
Output is correct |
13 |
Correct |
264 ms |
9212 KB |
Output is correct |
14 |
Correct |
216 ms |
9016 KB |
Output is correct |
15 |
Correct |
200 ms |
9092 KB |
Output is correct |
16 |
Correct |
201 ms |
9076 KB |
Output is correct |
17 |
Correct |
216 ms |
9076 KB |
Output is correct |
18 |
Correct |
217 ms |
9056 KB |
Output is correct |
19 |
Correct |
198 ms |
9064 KB |
Output is correct |
20 |
Correct |
216 ms |
9060 KB |
Output is correct |
21 |
Correct |
172 ms |
9756 KB |
Output is correct |
22 |
Correct |
187 ms |
9712 KB |
Output is correct |
23 |
Correct |
168 ms |
9460 KB |
Output is correct |
24 |
Correct |
198 ms |
9484 KB |
Output is correct |
25 |
Correct |
227 ms |
9200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
3168 KB |
Output is correct |
2 |
Correct |
28 ms |
3320 KB |
Output is correct |
3 |
Correct |
232 ms |
9524 KB |
Output is correct |
4 |
Correct |
240 ms |
9888 KB |
Output is correct |
5 |
Correct |
321 ms |
10892 KB |
Output is correct |
6 |
Correct |
302 ms |
10688 KB |
Output is correct |
7 |
Correct |
294 ms |
10636 KB |
Output is correct |
8 |
Correct |
296 ms |
10748 KB |
Output is correct |
9 |
Correct |
254 ms |
8644 KB |
Output is correct |
10 |
Correct |
207 ms |
8960 KB |
Output is correct |
11 |
Correct |
256 ms |
9132 KB |
Output is correct |
12 |
Correct |
275 ms |
10212 KB |
Output is correct |
13 |
Correct |
303 ms |
10444 KB |
Output is correct |
14 |
Correct |
304 ms |
10548 KB |
Output is correct |
15 |
Correct |
275 ms |
10536 KB |
Output is correct |
16 |
Correct |
261 ms |
9544 KB |
Output is correct |
17 |
Correct |
180 ms |
9840 KB |
Output is correct |
18 |
Correct |
164 ms |
9856 KB |
Output is correct |
19 |
Correct |
163 ms |
9852 KB |
Output is correct |
20 |
Correct |
207 ms |
9964 KB |
Output is correct |
21 |
Correct |
315 ms |
10412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
3192 KB |
Output is correct |
2 |
Correct |
30 ms |
3320 KB |
Output is correct |
3 |
Correct |
242 ms |
9584 KB |
Output is correct |
4 |
Correct |
285 ms |
9740 KB |
Output is correct |
5 |
Correct |
276 ms |
10012 KB |
Output is correct |
6 |
Correct |
310 ms |
10716 KB |
Output is correct |
7 |
Correct |
224 ms |
9424 KB |
Output is correct |
8 |
Correct |
201 ms |
9760 KB |
Output is correct |
9 |
Correct |
257 ms |
9936 KB |
Output is correct |
10 |
Correct |
309 ms |
10664 KB |
Output is correct |
11 |
Correct |
275 ms |
10772 KB |
Output is correct |
12 |
Correct |
302 ms |
10720 KB |
Output is correct |
13 |
Correct |
241 ms |
9160 KB |
Output is correct |
14 |
Correct |
239 ms |
8896 KB |
Output is correct |
15 |
Correct |
237 ms |
9172 KB |
Output is correct |
16 |
Correct |
261 ms |
8992 KB |
Output is correct |
17 |
Correct |
265 ms |
9156 KB |
Output is correct |
18 |
Correct |
219 ms |
8900 KB |
Output is correct |
19 |
Correct |
289 ms |
10128 KB |
Output is correct |
20 |
Correct |
285 ms |
10364 KB |
Output is correct |
21 |
Correct |
324 ms |
10500 KB |
Output is correct |
22 |
Correct |
308 ms |
10484 KB |
Output is correct |
23 |
Correct |
307 ms |
10496 KB |
Output is correct |
24 |
Correct |
311 ms |
10500 KB |
Output is correct |
25 |
Correct |
304 ms |
10696 KB |
Output is correct |
26 |
Correct |
318 ms |
10720 KB |
Output is correct |
27 |
Correct |
195 ms |
9936 KB |
Output is correct |
28 |
Correct |
191 ms |
9748 KB |
Output is correct |
29 |
Correct |
197 ms |
9856 KB |
Output is correct |
30 |
Correct |
195 ms |
9880 KB |
Output is correct |
31 |
Correct |
232 ms |
9844 KB |
Output is correct |
32 |
Correct |
215 ms |
9728 KB |
Output is correct |
33 |
Correct |
190 ms |
9880 KB |
Output is correct |
34 |
Correct |
198 ms |
9860 KB |
Output is correct |
35 |
Correct |
194 ms |
9872 KB |
Output is correct |
36 |
Correct |
198 ms |
9736 KB |
Output is correct |
37 |
Correct |
195 ms |
10060 KB |
Output is correct |
38 |
Correct |
218 ms |
9828 KB |
Output is correct |
39 |
Correct |
303 ms |
10464 KB |
Output is correct |
40 |
Correct |
301 ms |
10616 KB |
Output is correct |
41 |
Correct |
265 ms |
10472 KB |
Output is correct |
42 |
Correct |
293 ms |
10516 KB |
Output is correct |