#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
const int MAXN = 1e5 + 3e2;
int N;
vector<pair<int, int>> g[MAXN];
void bfs(int root, vector<int> &d, vector<int> &edges, vector<int> &p){
queue<int> q;
vector<bool> used(N, false);
used[root] = true;
q.push(root);
d[root] = 0;
p[root] = -1;
while (!q.empty()){
int x = q.front(); q.pop();
for (auto e : g[x]){
int y = e.first, i = e.second;
if (!used[y]){
used[y] = true;
q.push(y);
d[y] = d[x] + 1;
p[y] = i;
edges.push_back(i);
}
}
}
}
vector<int> vec;
void find_pair(int _N, vector<int> U, vector<int> V, int A, int B) {
N = _N;
int M = U.size();
for (int i = 0; i < M; i++){
g[U[i]].emplace_back(V[i], i);
g[V[i]].emplace_back(U[i], i);
}
vector<int> w(M, 0);
ll onlyA = ask(w);
int ind = 0;
int l = 0, r = M - 1;
while (l <= r){
int mid = (l + r) >> 1;
fill(all(w), 0);
for (int i = 0; i <= mid; i++) w[i] = 1;
ll res = ask(w);
if (res != onlyA){
ind = mid;
r = mid - 1;
} else l = mid + 1;
}
int u = U[ind], v = V[ind];
// cerr << u << ' ' << v << endl;
vector<int> du(N), dv(N), pu(N), pv(N);
vector<int> eu, ev;
bfs(u, du, eu, pu);
bfs(v, dv, ev, pv);
pu[u] = pv[v] = ind;
for (int i = 0; i < g[U[ind]].size(); i++){
if (g[U[ind]][i].first == V[ind]) g[U[ind]].erase(g[U[ind]].begin() + i);
}
for (int i = 0; i < g[V[ind]].size(); i++){
if (g[V[ind]][i].first == U[ind]) g[V[ind]].erase(g[V[ind]].begin() + i);
}
vector<int> a, b;
for (int i = 0; i < N; i++){
if (du[i] < dv[i]) a.push_back(i);
if (dv[i] < du[i]) b.push_back(i);
}
sort(all(a), [&](int i, int j){
return du[i] < du[j];
});
sort(all(b), [&](int i, int j){
return dv[i] < dv[j];
});
// cerr << endl;
// for (int x : a) cerr << x << ' ' << pu[x] << endl; cerr << endl;
// for (int x : b) cerr << x << ' ' << pv[x] << endl; cerr << endl;
int S = -1, T = -1;
l = 0, r = a.size() - 1;
while (l <= r){
int mid = (l + r) >> 1;
fill(all(w), 1);
w[ind] = 0;
for (int i = 0; i <= mid; i++) w[pu[a[i]]] = 0;
for (int i : b) w[pv[i]] = 0;
if (ask(w) == onlyA){
S = a[mid];
r = mid - 1;
} else l = mid + 1;
}
l = 0, r = b.size() - 1;
while (l <= r){
int mid = (l + r) >> 1;
fill(all(w), 1);
w[ind] = 0;
for (int i = 0; i <= mid; i++) w[pv[b[i]]] = 0;
for (int i : a) w[pu[i]] = 0;
// cerr << "mid = " << mid << endl;
// for (int x : w) cerr << x << ' '; cerr << endl << endl;
if (ask(w) == onlyA){
T = b[mid];
r = mid - 1;
} else l = mid + 1;
}
// cerr << S << ' ' << T << endl;
answer(S, T);
}
Compilation message
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:79:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
79 | for (int i = 0; i < g[U[ind]].size(); i++){
| ~~^~~~~~~~~~~~~~~~~~
highway.cpp:82:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
82 | for (int i = 0; i < g[V[ind]].size(); i++){
| ~~^~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2632 KB |
Output is correct |
2 |
Correct |
3 ms |
2632 KB |
Output is correct |
3 |
Correct |
2 ms |
2632 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
2 ms |
2632 KB |
Output is correct |
6 |
Correct |
3 ms |
2632 KB |
Output is correct |
7 |
Correct |
2 ms |
2632 KB |
Output is correct |
8 |
Correct |
1 ms |
2632 KB |
Output is correct |
9 |
Correct |
2 ms |
2632 KB |
Output is correct |
10 |
Correct |
2 ms |
2632 KB |
Output is correct |
11 |
Correct |
2 ms |
2632 KB |
Output is correct |
12 |
Correct |
2 ms |
2632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2632 KB |
Output is correct |
2 |
Correct |
12 ms |
3600 KB |
Output is correct |
3 |
Correct |
168 ms |
10600 KB |
Output is correct |
4 |
Correct |
137 ms |
10692 KB |
Output is correct |
5 |
Correct |
176 ms |
10616 KB |
Output is correct |
6 |
Correct |
191 ms |
10668 KB |
Output is correct |
7 |
Correct |
136 ms |
10684 KB |
Output is correct |
8 |
Correct |
166 ms |
10700 KB |
Output is correct |
9 |
Correct |
163 ms |
10688 KB |
Output is correct |
10 |
Correct |
139 ms |
10656 KB |
Output is correct |
11 |
Correct |
187 ms |
10120 KB |
Output is correct |
12 |
Correct |
176 ms |
10264 KB |
Output is correct |
13 |
Correct |
145 ms |
10156 KB |
Output is correct |
14 |
Correct |
148 ms |
10036 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
3528 KB |
Output is correct |
2 |
Correct |
29 ms |
4196 KB |
Output is correct |
3 |
Correct |
48 ms |
5120 KB |
Output is correct |
4 |
Correct |
112 ms |
9968 KB |
Output is correct |
5 |
Correct |
101 ms |
9964 KB |
Output is correct |
6 |
Correct |
110 ms |
10260 KB |
Output is correct |
7 |
Correct |
137 ms |
10152 KB |
Output is correct |
8 |
Correct |
114 ms |
9968 KB |
Output is correct |
9 |
Correct |
111 ms |
10060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2708 KB |
Output is correct |
2 |
Correct |
18 ms |
3572 KB |
Output is correct |
3 |
Correct |
91 ms |
9100 KB |
Output is correct |
4 |
Correct |
156 ms |
10644 KB |
Output is correct |
5 |
Correct |
125 ms |
10672 KB |
Output is correct |
6 |
Correct |
163 ms |
10672 KB |
Output is correct |
7 |
Correct |
134 ms |
10728 KB |
Output is correct |
8 |
Correct |
138 ms |
10720 KB |
Output is correct |
9 |
Correct |
189 ms |
10672 KB |
Output is correct |
10 |
Correct |
143 ms |
10656 KB |
Output is correct |
11 |
Correct |
191 ms |
10112 KB |
Output is correct |
12 |
Correct |
161 ms |
10036 KB |
Output is correct |
13 |
Correct |
218 ms |
10160 KB |
Output is correct |
14 |
Correct |
173 ms |
10120 KB |
Output is correct |
15 |
Correct |
108 ms |
10692 KB |
Output is correct |
16 |
Correct |
107 ms |
10756 KB |
Output is correct |
17 |
Correct |
212 ms |
10108 KB |
Output is correct |
18 |
Correct |
191 ms |
10036 KB |
Output is correct |
19 |
Correct |
105 ms |
10688 KB |
Output is correct |
20 |
Correct |
207 ms |
10032 KB |
Output is correct |
21 |
Correct |
123 ms |
10976 KB |
Output is correct |
22 |
Correct |
138 ms |
10972 KB |
Output is correct |
23 |
Correct |
118 ms |
10932 KB |
Output is correct |
24 |
Correct |
170 ms |
10736 KB |
Output is correct |
25 |
Correct |
187 ms |
10176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
3528 KB |
Output is correct |
2 |
Correct |
17 ms |
3660 KB |
Output is correct |
3 |
Correct |
156 ms |
11020 KB |
Output is correct |
4 |
Correct |
183 ms |
11264 KB |
Output is correct |
5 |
Correct |
247 ms |
12564 KB |
Output is correct |
6 |
Correct |
194 ms |
12300 KB |
Output is correct |
7 |
Correct |
242 ms |
12168 KB |
Output is correct |
8 |
Correct |
249 ms |
12224 KB |
Output is correct |
9 |
Correct |
124 ms |
9088 KB |
Output is correct |
10 |
Correct |
140 ms |
9564 KB |
Output is correct |
11 |
Correct |
138 ms |
10092 KB |
Output is correct |
12 |
Correct |
183 ms |
11460 KB |
Output is correct |
13 |
Correct |
197 ms |
11968 KB |
Output is correct |
14 |
Correct |
272 ms |
12252 KB |
Output is correct |
15 |
Correct |
190 ms |
12308 KB |
Output is correct |
16 |
Correct |
147 ms |
10228 KB |
Output is correct |
17 |
Correct |
122 ms |
10804 KB |
Output is correct |
18 |
Correct |
160 ms |
11012 KB |
Output is correct |
19 |
Correct |
138 ms |
10920 KB |
Output is correct |
20 |
Correct |
157 ms |
11040 KB |
Output is correct |
21 |
Correct |
207 ms |
12440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
3528 KB |
Output is correct |
2 |
Correct |
22 ms |
3652 KB |
Output is correct |
3 |
Correct |
155 ms |
11016 KB |
Output is correct |
4 |
Correct |
197 ms |
11008 KB |
Output is correct |
5 |
Correct |
198 ms |
11296 KB |
Output is correct |
6 |
Correct |
199 ms |
12204 KB |
Output is correct |
7 |
Correct |
160 ms |
11032 KB |
Output is correct |
8 |
Correct |
151 ms |
11244 KB |
Output is correct |
9 |
Correct |
168 ms |
11332 KB |
Output is correct |
10 |
Correct |
213 ms |
12396 KB |
Output is correct |
11 |
Correct |
255 ms |
12352 KB |
Output is correct |
12 |
Correct |
187 ms |
12208 KB |
Output is correct |
13 |
Correct |
141 ms |
10052 KB |
Output is correct |
14 |
Correct |
134 ms |
9444 KB |
Output is correct |
15 |
Correct |
142 ms |
10192 KB |
Output is correct |
16 |
Correct |
134 ms |
9432 KB |
Output is correct |
17 |
Correct |
150 ms |
10064 KB |
Output is correct |
18 |
Correct |
166 ms |
9496 KB |
Output is correct |
19 |
Correct |
175 ms |
11548 KB |
Output is correct |
20 |
Correct |
219 ms |
11992 KB |
Output is correct |
21 |
Correct |
183 ms |
12288 KB |
Output is correct |
22 |
Correct |
180 ms |
12236 KB |
Output is correct |
23 |
Correct |
222 ms |
12352 KB |
Output is correct |
24 |
Correct |
196 ms |
12460 KB |
Output is correct |
25 |
Correct |
246 ms |
12156 KB |
Output is correct |
26 |
Correct |
216 ms |
12320 KB |
Output is correct |
27 |
Correct |
159 ms |
10956 KB |
Output is correct |
28 |
Correct |
126 ms |
10868 KB |
Output is correct |
29 |
Correct |
153 ms |
11160 KB |
Output is correct |
30 |
Correct |
150 ms |
11036 KB |
Output is correct |
31 |
Correct |
121 ms |
10928 KB |
Output is correct |
32 |
Correct |
123 ms |
10892 KB |
Output is correct |
33 |
Correct |
142 ms |
11152 KB |
Output is correct |
34 |
Correct |
159 ms |
10992 KB |
Output is correct |
35 |
Correct |
141 ms |
10932 KB |
Output is correct |
36 |
Correct |
159 ms |
10932 KB |
Output is correct |
37 |
Correct |
172 ms |
11196 KB |
Output is correct |
38 |
Correct |
135 ms |
10996 KB |
Output is correct |
39 |
Correct |
234 ms |
12372 KB |
Output is correct |
40 |
Correct |
262 ms |
12488 KB |
Output is correct |
41 |
Correct |
242 ms |
12392 KB |
Output is correct |
42 |
Correct |
204 ms |
12396 KB |
Output is correct |