#include <bits/stdc++.h>
#include "highway.h"
using namespace std;
#define ll long long
void find_pair(int N, vector<int> U, vector<int> V, int A, int B) {
int M = size(U), x = 0, u, d[2][N];
ll least = ask(vector<int> (M));
for(int b = 1<<17; b/=2; ) if(x + b < M) {
vector<int> w(M);
fill(begin(w), begin(w) + x + b, 1);
if(ask(w) == least) x |= b;
}
array<int, 2> S = {U[x], V[x]}, ans {};
vector<array<int, 2>> g[N], a;
for(int i = x; i < M; i++) {
g[U[i]].push_back({V[i], i});
g[V[i]].push_back({U[i], i});
}
for(int k : {0, 1}) {
fill(d[k], d[k] + N, N);
queue<int> q;
d[k][S[k]] = 0;
q.push(S[k]);
while(!empty(q)) {
u = q.front(); q.pop();
for(auto &[v, e] : g[u]) if(d[k][v] > d[k][u] + 1) d[k][v] = d[k][u] + 1, q.push(v);
}
}
for(int k : {0, 1}) {
a.clear();
for(int i = 0; i < N; i++) if(d[k][i] < d[!k][i]) a.push_back({-d[k][i], i});
sort(a.begin(), a.end());
for(int b = 1<<17; b/=2; ) if(ans[k] + b < size(a)) {
vector<int> w(M);
fill(begin(w), begin(w) + x, 1);
for(int i = ans[k] + b; --i >= 0; ) for(auto &[v, e] : g[a[i][1]]) w[e] = 1;
if(ask(w) == least) ans[k] |= b;
}
ans[k] = a[ans[k]][1];
}
answer(ans[0], ans[1]);
}
Compilation message
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:35:44: warning: comparison of integer expressions of different signedness: 'std::array<int, 2>::value_type' {aka 'int'} and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for(int b = 1<<17; b/=2; ) if(ans[k] + b < size(a)) {
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
0 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
300 KB |
Output is correct |
10 |
Correct |
0 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
1 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
13 ms |
1232 KB |
Output is correct |
3 |
Correct |
151 ms |
9280 KB |
Output is correct |
4 |
Correct |
116 ms |
9340 KB |
Output is correct |
5 |
Correct |
88 ms |
9420 KB |
Output is correct |
6 |
Correct |
93 ms |
8632 KB |
Output is correct |
7 |
Correct |
98 ms |
8496 KB |
Output is correct |
8 |
Correct |
110 ms |
9412 KB |
Output is correct |
9 |
Correct |
101 ms |
8568 KB |
Output is correct |
10 |
Correct |
87 ms |
8812 KB |
Output is correct |
11 |
Correct |
72 ms |
7944 KB |
Output is correct |
12 |
Correct |
136 ms |
8348 KB |
Output is correct |
13 |
Correct |
97 ms |
8800 KB |
Output is correct |
14 |
Correct |
86 ms |
8772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
1232 KB |
Output is correct |
2 |
Correct |
18 ms |
2000 KB |
Output is correct |
3 |
Correct |
54 ms |
1980 KB |
Output is correct |
4 |
Correct |
89 ms |
7220 KB |
Output is correct |
5 |
Correct |
82 ms |
7256 KB |
Output is correct |
6 |
Correct |
61 ms |
8248 KB |
Output is correct |
7 |
Correct |
71 ms |
5140 KB |
Output is correct |
8 |
Correct |
58 ms |
7524 KB |
Output is correct |
9 |
Correct |
75 ms |
6048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
12 ms |
1220 KB |
Output is correct |
3 |
Correct |
77 ms |
7344 KB |
Output is correct |
4 |
Correct |
93 ms |
9384 KB |
Output is correct |
5 |
Correct |
74 ms |
7728 KB |
Output is correct |
6 |
Correct |
72 ms |
8040 KB |
Output is correct |
7 |
Correct |
98 ms |
8500 KB |
Output is correct |
8 |
Correct |
95 ms |
8036 KB |
Output is correct |
9 |
Correct |
119 ms |
9316 KB |
Output is correct |
10 |
Correct |
109 ms |
8692 KB |
Output is correct |
11 |
Correct |
103 ms |
8776 KB |
Output is correct |
12 |
Correct |
85 ms |
8204 KB |
Output is correct |
13 |
Correct |
112 ms |
8284 KB |
Output is correct |
14 |
Correct |
85 ms |
7948 KB |
Output is correct |
15 |
Correct |
125 ms |
7888 KB |
Output is correct |
16 |
Correct |
55 ms |
7092 KB |
Output is correct |
17 |
Correct |
111 ms |
8804 KB |
Output is correct |
18 |
Correct |
137 ms |
8772 KB |
Output is correct |
19 |
Correct |
78 ms |
7720 KB |
Output is correct |
20 |
Correct |
67 ms |
7724 KB |
Output is correct |
21 |
Correct |
66 ms |
7580 KB |
Output is correct |
22 |
Correct |
70 ms |
6252 KB |
Output is correct |
23 |
Correct |
94 ms |
8976 KB |
Output is correct |
24 |
Correct |
89 ms |
8908 KB |
Output is correct |
25 |
Correct |
90 ms |
8932 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
1232 KB |
Output is correct |
2 |
Correct |
13 ms |
1256 KB |
Output is correct |
3 |
Correct |
140 ms |
9628 KB |
Output is correct |
4 |
Correct |
146 ms |
8944 KB |
Output is correct |
5 |
Correct |
165 ms |
9768 KB |
Output is correct |
6 |
Correct |
192 ms |
10588 KB |
Output is correct |
7 |
Correct |
127 ms |
10392 KB |
Output is correct |
8 |
Correct |
121 ms |
10080 KB |
Output is correct |
9 |
Correct |
127 ms |
3892 KB |
Output is correct |
10 |
Correct |
87 ms |
5452 KB |
Output is correct |
11 |
Correct |
134 ms |
6412 KB |
Output is correct |
12 |
Correct |
155 ms |
9652 KB |
Output is correct |
13 |
Correct |
135 ms |
10080 KB |
Output is correct |
14 |
Correct |
134 ms |
10216 KB |
Output is correct |
15 |
Correct |
145 ms |
10832 KB |
Output is correct |
16 |
Correct |
109 ms |
7828 KB |
Output is correct |
17 |
Correct |
103 ms |
9072 KB |
Output is correct |
18 |
Correct |
100 ms |
7712 KB |
Output is correct |
19 |
Correct |
105 ms |
9332 KB |
Output is correct |
20 |
Correct |
83 ms |
8612 KB |
Output is correct |
21 |
Correct |
185 ms |
11228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
1232 KB |
Output is correct |
2 |
Correct |
13 ms |
1380 KB |
Output is correct |
3 |
Correct |
122 ms |
9184 KB |
Output is correct |
4 |
Correct |
146 ms |
9148 KB |
Output is correct |
5 |
Correct |
137 ms |
9284 KB |
Output is correct |
6 |
Correct |
145 ms |
10444 KB |
Output is correct |
7 |
Correct |
167 ms |
9664 KB |
Output is correct |
8 |
Correct |
131 ms |
9900 KB |
Output is correct |
9 |
Correct |
136 ms |
9500 KB |
Output is correct |
10 |
Correct |
119 ms |
10524 KB |
Output is correct |
11 |
Correct |
209 ms |
10240 KB |
Output is correct |
12 |
Correct |
182 ms |
10596 KB |
Output is correct |
13 |
Correct |
106 ms |
4232 KB |
Output is correct |
14 |
Correct |
71 ms |
3680 KB |
Output is correct |
15 |
Correct |
107 ms |
8012 KB |
Output is correct |
16 |
Correct |
78 ms |
5404 KB |
Output is correct |
17 |
Correct |
87 ms |
6532 KB |
Output is correct |
18 |
Correct |
91 ms |
5440 KB |
Output is correct |
19 |
Correct |
132 ms |
9296 KB |
Output is correct |
20 |
Correct |
149 ms |
10064 KB |
Output is correct |
21 |
Correct |
174 ms |
10812 KB |
Output is correct |
22 |
Correct |
128 ms |
10656 KB |
Output is correct |
23 |
Correct |
187 ms |
10328 KB |
Output is correct |
24 |
Correct |
129 ms |
10304 KB |
Output is correct |
25 |
Correct |
142 ms |
9932 KB |
Output is correct |
26 |
Correct |
150 ms |
10396 KB |
Output is correct |
27 |
Correct |
111 ms |
8360 KB |
Output is correct |
28 |
Correct |
75 ms |
9208 KB |
Output is correct |
29 |
Correct |
87 ms |
9792 KB |
Output is correct |
30 |
Correct |
94 ms |
9584 KB |
Output is correct |
31 |
Correct |
96 ms |
9544 KB |
Output is correct |
32 |
Correct |
96 ms |
9376 KB |
Output is correct |
33 |
Correct |
104 ms |
9860 KB |
Output is correct |
34 |
Correct |
88 ms |
8512 KB |
Output is correct |
35 |
Correct |
72 ms |
8744 KB |
Output is correct |
36 |
Correct |
102 ms |
9364 KB |
Output is correct |
37 |
Correct |
118 ms |
9172 KB |
Output is correct |
38 |
Correct |
85 ms |
9404 KB |
Output is correct |
39 |
Correct |
208 ms |
11004 KB |
Output is correct |
40 |
Correct |
176 ms |
10952 KB |
Output is correct |
41 |
Correct |
172 ms |
11088 KB |
Output is correct |
42 |
Correct |
195 ms |
10500 KB |
Output is correct |