#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define fr first
#define sc second
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)
const int nmax = 90005;
const int mmax = 130005;
long long len_edges, a, b;
int N, M, goodedge;
vector<pair<int,int>>nod[nmax];
int find_lenght(int A, int B){
vector<int>w;
for(int i=0;i<M;i++) w.push_back(0);
long long lmao = ask(w);
return lmao / A;
}
int find_index(){
int l = 0, r = M - 1, ok = 0;
while(l <= r){
int mid = l + (r - l) / 2;
vector<int>w;
for(int i=0;i<mid;i++) w.push_back(0);
for(int i=mid;i<M;i++) w.push_back(1);
long long lmao = ask(w);
if(lmao > len_edges * a){
ok = mid;
l = mid + 1;
}
else{
r = mid - 1;
}
}
return ok;
}
vector<int> bfs(int vertex1, int vertex2, vector<int>U, vector<int>V){
int marked[M], marked2[M];
for(int i=0;i<M;i++) marked2[i] = 0;
queue<int>Q;
vector<int>interesting_egdes1, interesting_egdes2;
int marked_v[N], viz[N], par[N];
for(int i=0;i<N;i++){
marked_v[i] = 0;
viz[i] = 0;
par[i] = 0;
}
par[vertex1] = -1;
Q.push(vertex1);
viz[vertex1] = 1;
Q.push(vertex2);
viz[vertex2] = 1;
marked2[goodedge] = 1;
marked_v[vertex2] = 1;
while(Q.size()){
int x = Q.front();
Q.pop();
for(auto it : nod[x]){
if(!viz[it.fr]){
if(marked_v[x] == 0){
interesting_egdes1.push_back(it.sc);
}
if(marked_v[x] == 1){
interesting_egdes2.push_back(it.sc);
marked_v[it.fr] = 1;
}
marked2[it.sc] = 1;
par[it.fr] = x;
viz[it.fr] = 1;
Q.push(it.fr);
}
}
}
int ok = vertex2;
int l = 0, r = (int)interesting_egdes2.size() - 1;
reverse(all(interesting_egdes2));
while(l <= r){
int last = 0;
int mid = l + (r - l) / 2;
vector<int>w(M);
for(int i=0;i<M;i++){
if(!marked2[i]) w[i] = 1;
}
for(int i=0;i<=mid;i++){
w[interesting_egdes2[i]] = 1;
}
last = interesting_egdes2[mid];
if(par[U[last]] == V[last]){
last = U[last];
}
else{
last = V[last];
}
long long pls = ask(w);
if(pls != len_edges * a){
ok = last;
r = mid - 1;
}
else{
l = mid + 1;
}
}
vector<int>rs;
rs.push_back(ok);
ok = vertex1;
l = 0, r = (int)interesting_egdes1.size() - 1;
reverse(all(interesting_egdes1));
while(l <= r){
int last = 0;
int mid = l + (r - l) / 2;
vector<int>w(M);
for(int i=0;i<M;i++){
if(!marked2[i]) w[i] = 1;
}
for(int i=0;i<=mid;i++){
w[interesting_egdes1[i]] = 1;
}
last = interesting_egdes1[mid];
if(par[U[last]] == V[last]){
last = U[last];
}
else{
last = V[last];
}
long long pls = ask(w);
if(pls != len_edges * a){
ok = last;
r = mid - 1;
}
else{
l = mid + 1;
}
}
rs.push_back(ok);
return rs;
}
void find_pair(int n, vector<int> U, vector<int> V, int A, int B) {
M = (int)U.size();
N = n;
a = A, b = B;
for(int i=0;i<M;i++){
nod[U[i]].push_back({V[i], i});
nod[V[i]].push_back({U[i], i});
}
len_edges = find_lenght(A, B);
int indx = find_index();
goodedge = indx;
int vertex1 = U[indx];
int vertex2 = V[indx];
vector<int>ans = bfs(vertex1, vertex2, U, V);
answer(ans[0], ans[1]);
}
Compilation message
highway.cpp: In function 'std::vector<int> bfs(int, int, std::vector<int>, std::vector<int>)':
highway.cpp:49:9: warning: unused variable 'marked' [-Wunused-variable]
49 | int marked[M], marked2[M];
| ^~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2376 KB |
Output is correct |
2 |
Correct |
2 ms |
2376 KB |
Output is correct |
3 |
Correct |
2 ms |
2376 KB |
Output is correct |
4 |
Correct |
2 ms |
2376 KB |
Output is correct |
5 |
Correct |
2 ms |
2376 KB |
Output is correct |
6 |
Correct |
2 ms |
2376 KB |
Output is correct |
7 |
Correct |
2 ms |
2376 KB |
Output is correct |
8 |
Correct |
2 ms |
2376 KB |
Output is correct |
9 |
Correct |
2 ms |
2376 KB |
Output is correct |
10 |
Correct |
2 ms |
2376 KB |
Output is correct |
11 |
Correct |
2 ms |
2376 KB |
Output is correct |
12 |
Correct |
2 ms |
2376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2376 KB |
Output is correct |
2 |
Correct |
16 ms |
3272 KB |
Output is correct |
3 |
Correct |
146 ms |
10168 KB |
Output is correct |
4 |
Correct |
144 ms |
10264 KB |
Output is correct |
5 |
Correct |
149 ms |
10180 KB |
Output is correct |
6 |
Correct |
147 ms |
10176 KB |
Output is correct |
7 |
Correct |
147 ms |
10168 KB |
Output is correct |
8 |
Correct |
157 ms |
10172 KB |
Output is correct |
9 |
Correct |
152 ms |
10564 KB |
Output is correct |
10 |
Correct |
147 ms |
10176 KB |
Output is correct |
11 |
Correct |
162 ms |
9776 KB |
Output is correct |
12 |
Correct |
157 ms |
9656 KB |
Output is correct |
13 |
Correct |
152 ms |
9632 KB |
Output is correct |
14 |
Correct |
163 ms |
9612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
3120 KB |
Output is correct |
2 |
Correct |
30 ms |
3984 KB |
Output is correct |
3 |
Correct |
39 ms |
4876 KB |
Output is correct |
4 |
Correct |
120 ms |
9800 KB |
Output is correct |
5 |
Correct |
122 ms |
9816 KB |
Output is correct |
6 |
Correct |
120 ms |
9644 KB |
Output is correct |
7 |
Correct |
118 ms |
9732 KB |
Output is correct |
8 |
Correct |
124 ms |
9784 KB |
Output is correct |
9 |
Correct |
130 ms |
9704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2376 KB |
Output is correct |
2 |
Correct |
17 ms |
3172 KB |
Output is correct |
3 |
Correct |
113 ms |
8564 KB |
Output is correct |
4 |
Correct |
149 ms |
10216 KB |
Output is correct |
5 |
Correct |
142 ms |
10184 KB |
Output is correct |
6 |
Correct |
148 ms |
10220 KB |
Output is correct |
7 |
Correct |
145 ms |
10188 KB |
Output is correct |
8 |
Correct |
147 ms |
10172 KB |
Output is correct |
9 |
Correct |
147 ms |
10268 KB |
Output is correct |
10 |
Correct |
150 ms |
10168 KB |
Output is correct |
11 |
Correct |
165 ms |
9628 KB |
Output is correct |
12 |
Correct |
167 ms |
9916 KB |
Output is correct |
13 |
Correct |
167 ms |
9752 KB |
Output is correct |
14 |
Correct |
179 ms |
9680 KB |
Output is correct |
15 |
Correct |
147 ms |
10176 KB |
Output is correct |
16 |
Correct |
145 ms |
10300 KB |
Output is correct |
17 |
Correct |
151 ms |
9624 KB |
Output is correct |
18 |
Correct |
153 ms |
9688 KB |
Output is correct |
19 |
Correct |
143 ms |
10180 KB |
Output is correct |
20 |
Correct |
153 ms |
9608 KB |
Output is correct |
21 |
Correct |
128 ms |
10704 KB |
Output is correct |
22 |
Correct |
127 ms |
10692 KB |
Output is correct |
23 |
Correct |
141 ms |
10548 KB |
Output is correct |
24 |
Correct |
134 ms |
10612 KB |
Output is correct |
25 |
Correct |
150 ms |
9736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
3216 KB |
Output is correct |
2 |
Correct |
21 ms |
3392 KB |
Output is correct |
3 |
Correct |
181 ms |
10812 KB |
Output is correct |
4 |
Correct |
182 ms |
11548 KB |
Output is correct |
5 |
Correct |
259 ms |
12720 KB |
Output is correct |
6 |
Correct |
235 ms |
12720 KB |
Output is correct |
7 |
Correct |
240 ms |
12828 KB |
Output is correct |
8 |
Correct |
246 ms |
12504 KB |
Output is correct |
9 |
Correct |
182 ms |
9968 KB |
Output is correct |
10 |
Correct |
174 ms |
10420 KB |
Output is correct |
11 |
Correct |
183 ms |
10952 KB |
Output is correct |
12 |
Correct |
231 ms |
12060 KB |
Output is correct |
13 |
Correct |
242 ms |
12444 KB |
Output is correct |
14 |
Correct |
248 ms |
12488 KB |
Output is correct |
15 |
Correct |
236 ms |
12692 KB |
Output is correct |
16 |
Correct |
211 ms |
11208 KB |
Output is correct |
17 |
Correct |
139 ms |
10808 KB |
Output is correct |
18 |
Correct |
142 ms |
10976 KB |
Output is correct |
19 |
Correct |
141 ms |
10916 KB |
Output is correct |
20 |
Correct |
144 ms |
10980 KB |
Output is correct |
21 |
Correct |
233 ms |
12820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
3332 KB |
Output is correct |
2 |
Correct |
18 ms |
3236 KB |
Output is correct |
3 |
Correct |
164 ms |
10736 KB |
Output is correct |
4 |
Correct |
184 ms |
11220 KB |
Output is correct |
5 |
Correct |
195 ms |
11628 KB |
Output is correct |
6 |
Correct |
225 ms |
12700 KB |
Output is correct |
7 |
Correct |
182 ms |
11108 KB |
Output is correct |
8 |
Correct |
200 ms |
11332 KB |
Output is correct |
9 |
Correct |
175 ms |
11552 KB |
Output is correct |
10 |
Correct |
238 ms |
12676 KB |
Output is correct |
11 |
Correct |
240 ms |
12632 KB |
Output is correct |
12 |
Correct |
223 ms |
12700 KB |
Output is correct |
13 |
Correct |
182 ms |
10852 KB |
Output is correct |
14 |
Correct |
168 ms |
10424 KB |
Output is correct |
15 |
Correct |
184 ms |
10932 KB |
Output is correct |
16 |
Correct |
171 ms |
10428 KB |
Output is correct |
17 |
Correct |
180 ms |
10828 KB |
Output is correct |
18 |
Correct |
166 ms |
10480 KB |
Output is correct |
19 |
Correct |
232 ms |
12168 KB |
Output is correct |
20 |
Correct |
255 ms |
12272 KB |
Output is correct |
21 |
Correct |
244 ms |
12964 KB |
Output is correct |
22 |
Correct |
260 ms |
12692 KB |
Output is correct |
23 |
Correct |
247 ms |
12688 KB |
Output is correct |
24 |
Correct |
229 ms |
12716 KB |
Output is correct |
25 |
Correct |
237 ms |
12596 KB |
Output is correct |
26 |
Correct |
223 ms |
12744 KB |
Output is correct |
27 |
Correct |
138 ms |
10892 KB |
Output is correct |
28 |
Correct |
144 ms |
10816 KB |
Output is correct |
29 |
Correct |
152 ms |
11064 KB |
Output is correct |
30 |
Correct |
151 ms |
11064 KB |
Output is correct |
31 |
Correct |
143 ms |
10912 KB |
Output is correct |
32 |
Correct |
134 ms |
10784 KB |
Output is correct |
33 |
Correct |
147 ms |
11088 KB |
Output is correct |
34 |
Correct |
145 ms |
10944 KB |
Output is correct |
35 |
Correct |
138 ms |
10920 KB |
Output is correct |
36 |
Correct |
140 ms |
10872 KB |
Output is correct |
37 |
Correct |
144 ms |
10992 KB |
Output is correct |
38 |
Correct |
149 ms |
10976 KB |
Output is correct |
39 |
Correct |
219 ms |
12808 KB |
Output is correct |
40 |
Correct |
239 ms |
12784 KB |
Output is correct |
41 |
Correct |
249 ms |
12828 KB |
Output is correct |
42 |
Correct |
242 ms |
12692 KB |
Output is correct |