#include "highway.h"
#include "bits/stdc++.h"
using namespace std;
const int N = 4e5 + 10;
vector<pair<int, int>> adj[N];
long long start;
int query(int s, int m, vector<pair<int, int>> edges, vector<int> paiu) {
if(edges.empty()) return s;
int l = 0, r = (int)edges.size() - 1;
vector<int> c(m, 0);
for(auto x: paiu) c[x] = 1;
reverse(edges.begin(), edges.end());
int pos = -1;
while(l <= r) {
int mid = l + r >> 1;
vector<int> rem = c;
for(int j = 0; j <= mid; ++j) {
c[edges[j].first] = 1;
}
if(ask(c) > start) {
pos = mid, r = mid - 1;
} else l = mid + 1;
c = rem;
}
if(pos == -1) return s;
return edges[pos].second;
}
void find_pair(int n, vector<int> u, vector<int> v, int a, int b) {
int m = u.size();
start = ask(vector<int>(m, 0));
for(int i = 0; i < m; ++i) {
adj[u[i]].push_back({i, v[i]});
adj[v[i]].push_back({i, u[i]});
}
int l = 0, r = m - 1, p = -1;
while(l <= r) {
int mid = l + r >> 1;
vector<int> qr(m, 0);
for(int j = 0; j <= mid; ++j) qr[j] = 1;
if(ask(qr) > start) {
p = mid;
r = mid - 1;
} else l = mid + 1;
}
assert(p != -1);
vector<vector<int>> dist(2, vector<int>(n, -1));
vector<int> nodes = {u[p], v[p]};
for(int j = 0; j < 2; ++j) {
queue<int> q; q.push(nodes[j]);
dist[j][nodes[j]] = 0;
while(!q.empty()) {
int u = q.front();
q.pop();
for(auto x: adj[u]) {
int v = x.second;
if(dist[j][v] == -1) {
dist[j][v] = dist[j][u] + 1;
q.push(v);
}
}
}
}
vector<int> ans(2);
for(int j = 0; j < 2; ++j) {
vector<pair<int, int>> edges;
queue<int> q; q.push(nodes[j]);
vector<int> d(n, -1), paiu;
d[nodes[j]] = 0;
while(!q.empty()) {
int u = q.front();
q.pop();
for(auto x: adj[u]) {
int idx = x.first, v = x.second;
if(dist[j][v] < dist[j ^ 1][v]) {
if(d[v] == -1) {
d[v] = d[u] + 1;
q.push(v);
edges.push_back({idx, v});
} else if(d[v] == d[u] + 1) {
paiu.push_back(idx);
}
} else if(idx != p) {
paiu.push_back(idx);
}
}
}
ans[j] = query(nodes[j], m, edges, paiu);
}
//assert(ans[0] == 0 || ans[1] == 0);
answer(ans[0], ans[1]);
}
Compilation message
highway.cpp: In function 'int query(int, int, std::vector<std::pair<int, int> >, std::vector<int>)':
highway.cpp:16:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
16 | int mid = l + r >> 1;
| ~~^~~
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:39:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
39 | int mid = l + r >> 1;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9680 KB |
Output is correct |
2 |
Correct |
5 ms |
9696 KB |
Output is correct |
3 |
Correct |
5 ms |
9672 KB |
Output is correct |
4 |
Correct |
5 ms |
9680 KB |
Output is correct |
5 |
Correct |
5 ms |
9692 KB |
Output is correct |
6 |
Correct |
5 ms |
9680 KB |
Output is correct |
7 |
Correct |
5 ms |
9680 KB |
Output is correct |
8 |
Correct |
5 ms |
9656 KB |
Output is correct |
9 |
Correct |
5 ms |
9604 KB |
Output is correct |
10 |
Correct |
5 ms |
9680 KB |
Output is correct |
11 |
Correct |
5 ms |
9680 KB |
Output is correct |
12 |
Correct |
5 ms |
9680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9716 KB |
Output is correct |
2 |
Correct |
18 ms |
10612 KB |
Output is correct |
3 |
Correct |
163 ms |
18008 KB |
Output is correct |
4 |
Correct |
126 ms |
17976 KB |
Output is correct |
5 |
Correct |
117 ms |
18008 KB |
Output is correct |
6 |
Correct |
113 ms |
18064 KB |
Output is correct |
7 |
Correct |
151 ms |
17980 KB |
Output is correct |
8 |
Correct |
166 ms |
18016 KB |
Output is correct |
9 |
Correct |
150 ms |
18008 KB |
Output is correct |
10 |
Correct |
119 ms |
18036 KB |
Output is correct |
11 |
Correct |
129 ms |
16860 KB |
Output is correct |
12 |
Correct |
127 ms |
17140 KB |
Output is correct |
13 |
Correct |
124 ms |
17412 KB |
Output is correct |
14 |
Correct |
129 ms |
17404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
10524 KB |
Output is correct |
2 |
Correct |
24 ms |
11380 KB |
Output is correct |
3 |
Correct |
34 ms |
12144 KB |
Output is correct |
4 |
Correct |
136 ms |
17256 KB |
Output is correct |
5 |
Correct |
135 ms |
17184 KB |
Output is correct |
6 |
Correct |
109 ms |
17164 KB |
Output is correct |
7 |
Correct |
103 ms |
17380 KB |
Output is correct |
8 |
Correct |
106 ms |
17028 KB |
Output is correct |
9 |
Correct |
103 ms |
17080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
9680 KB |
Output is correct |
2 |
Correct |
21 ms |
10448 KB |
Output is correct |
3 |
Correct |
107 ms |
16188 KB |
Output is correct |
4 |
Correct |
152 ms |
18004 KB |
Output is correct |
5 |
Correct |
178 ms |
18012 KB |
Output is correct |
6 |
Correct |
113 ms |
17996 KB |
Output is correct |
7 |
Correct |
127 ms |
18012 KB |
Output is correct |
8 |
Correct |
156 ms |
18000 KB |
Output is correct |
9 |
Correct |
154 ms |
17916 KB |
Output is correct |
10 |
Correct |
165 ms |
18088 KB |
Output is correct |
11 |
Correct |
127 ms |
17428 KB |
Output is correct |
12 |
Correct |
136 ms |
17244 KB |
Output is correct |
13 |
Correct |
189 ms |
17164 KB |
Output is correct |
14 |
Correct |
128 ms |
16952 KB |
Output is correct |
15 |
Correct |
119 ms |
18064 KB |
Output is correct |
16 |
Correct |
109 ms |
18004 KB |
Output is correct |
17 |
Correct |
170 ms |
17328 KB |
Output is correct |
18 |
Correct |
146 ms |
17496 KB |
Output is correct |
19 |
Correct |
172 ms |
18016 KB |
Output is correct |
20 |
Correct |
128 ms |
17352 KB |
Output is correct |
21 |
Correct |
105 ms |
18200 KB |
Output is correct |
22 |
Correct |
103 ms |
18180 KB |
Output is correct |
23 |
Correct |
141 ms |
17704 KB |
Output is correct |
24 |
Correct |
122 ms |
17660 KB |
Output is correct |
25 |
Correct |
158 ms |
17468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
10524 KB |
Output is correct |
2 |
Correct |
22 ms |
10676 KB |
Output is correct |
3 |
Correct |
175 ms |
18292 KB |
Output is correct |
4 |
Correct |
184 ms |
18368 KB |
Output is correct |
5 |
Correct |
232 ms |
19688 KB |
Output is correct |
6 |
Correct |
206 ms |
19588 KB |
Output is correct |
7 |
Correct |
189 ms |
19276 KB |
Output is correct |
8 |
Correct |
195 ms |
19064 KB |
Output is correct |
9 |
Correct |
148 ms |
17712 KB |
Output is correct |
10 |
Correct |
197 ms |
18360 KB |
Output is correct |
11 |
Correct |
151 ms |
18376 KB |
Output is correct |
12 |
Correct |
204 ms |
18808 KB |
Output is correct |
13 |
Correct |
230 ms |
18912 KB |
Output is correct |
14 |
Correct |
234 ms |
19188 KB |
Output is correct |
15 |
Correct |
201 ms |
19600 KB |
Output is correct |
16 |
Correct |
210 ms |
17968 KB |
Output is correct |
17 |
Correct |
160 ms |
18148 KB |
Output is correct |
18 |
Correct |
107 ms |
18376 KB |
Output is correct |
19 |
Correct |
139 ms |
18276 KB |
Output is correct |
20 |
Correct |
147 ms |
18400 KB |
Output is correct |
21 |
Correct |
195 ms |
19744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
10568 KB |
Output is correct |
2 |
Correct |
20 ms |
10704 KB |
Output is correct |
3 |
Correct |
158 ms |
17772 KB |
Output is correct |
4 |
Correct |
143 ms |
18140 KB |
Output is correct |
5 |
Correct |
177 ms |
18444 KB |
Output is correct |
6 |
Correct |
174 ms |
19160 KB |
Output is correct |
7 |
Correct |
185 ms |
18432 KB |
Output is correct |
8 |
Correct |
138 ms |
18460 KB |
Output is correct |
9 |
Correct |
159 ms |
18080 KB |
Output is correct |
10 |
Correct |
229 ms |
19296 KB |
Output is correct |
11 |
Correct |
215 ms |
19268 KB |
Output is correct |
12 |
Correct |
207 ms |
19064 KB |
Output is correct |
13 |
Correct |
187 ms |
18660 KB |
Output is correct |
14 |
Correct |
153 ms |
18152 KB |
Output is correct |
15 |
Correct |
189 ms |
18672 KB |
Output is correct |
16 |
Correct |
181 ms |
18076 KB |
Output is correct |
17 |
Correct |
143 ms |
18672 KB |
Output is correct |
18 |
Correct |
173 ms |
18332 KB |
Output is correct |
19 |
Correct |
179 ms |
18856 KB |
Output is correct |
20 |
Correct |
168 ms |
19300 KB |
Output is correct |
21 |
Correct |
213 ms |
19260 KB |
Output is correct |
22 |
Correct |
201 ms |
19268 KB |
Output is correct |
23 |
Correct |
255 ms |
19308 KB |
Output is correct |
24 |
Correct |
179 ms |
19152 KB |
Output is correct |
25 |
Correct |
234 ms |
19476 KB |
Output is correct |
26 |
Correct |
190 ms |
19472 KB |
Output is correct |
27 |
Correct |
101 ms |
18292 KB |
Output is correct |
28 |
Correct |
152 ms |
18312 KB |
Output is correct |
29 |
Correct |
114 ms |
18520 KB |
Output is correct |
30 |
Correct |
145 ms |
18412 KB |
Output is correct |
31 |
Correct |
110 ms |
18284 KB |
Output is correct |
32 |
Correct |
108 ms |
18196 KB |
Output is correct |
33 |
Correct |
133 ms |
18472 KB |
Output is correct |
34 |
Correct |
105 ms |
18284 KB |
Output is correct |
35 |
Correct |
134 ms |
18268 KB |
Output is correct |
36 |
Correct |
145 ms |
18164 KB |
Output is correct |
37 |
Correct |
107 ms |
18548 KB |
Output is correct |
38 |
Correct |
150 ms |
18432 KB |
Output is correct |
39 |
Correct |
228 ms |
19992 KB |
Output is correct |
40 |
Correct |
170 ms |
19780 KB |
Output is correct |
41 |
Correct |
157 ms |
19948 KB |
Output is correct |
42 |
Correct |
230 ms |
19508 KB |
Output is correct |