#include "highway.h"
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
int n, m;
ll A, B;
vector<vector<pair<int, int>>> graph;
void find_pair(int _n, vector<int> U, vector<int> V, int _A, int _B){
swap(n, _n);
m = U.size();
A = _A, B = _B;
graph.resize(n);
for(int i = 0; i < m; i++){
graph[U[i]].pb({V[i], i});
graph[V[i]].pb({U[i], i});
}
ll def = ask(vector<int>(m, 0));
int a = 0, b = m-1;
while(a < b){
int md = (a+b)/2;
vector<int> w(m, 0);
for(int i = 0; i <= md; i++) w[i] = 1;
ll x = ask(w);
if(x > def) b = md;
else a = md+1;
}
int e = a;
int u = U[e], v = V[e];
vector<int> disu(n, -1);
vector<int> pu(n, -1), wu(m, 1);
queue<int> Q;
disu[u] = 0;
Q.push(u);
disu[v] = 1;
pu[v] = e;
wu[e] = 0;
Q.push(v);
while(!Q.empty()){
int nd = Q.front(); Q.pop();
for(auto [x, i]: graph[nd]) if(disu[x] == -1){
disu[x] = disu[nd]+1;
pu[x] = i;
wu[i] = 0;
Q.push(x);
}
}
vector<int> disv(n, -1);
vector<int> pv(n, -1), wv(m, 1);
disv[v] = 0;
Q.push(v);
disv[u] = 1;
pv[u] = e;
wv[e] = 0;
Q.push(u);
while(!Q.empty()){
int nd = Q.front(); Q.pop();
for(auto [x, i]: graph[nd]) if(disv[x] == -1){
disv[x] = disv[nd]+1;
pv[x] = i;
wv[i] = 0;
Q.push(x);
}
}
vector<int> unodes, vnodes;
for(int i = 0; i < n; i++){
if(disu[i] == disv[i]) continue;
if(disu[i] < disv[i]) unodes.pb(i);
else vnodes.pb(i);
}
sort(unodes.begin(), unodes.end(), [&](int x, int y){
return disu[x] > disu[y];
});
sort(vnodes.begin(), vnodes.end(), [&](int x, int y){
return disv[x] > disv[y];
});
int s, t;
a = 0, b = int(unodes.size())-1;
while(a < b){
int md = (a+b)/2;
vector<int> w = wu;
for(int i = 0; i <= md; i++) if(pu[unodes[i]] != -1) w[pu[unodes[i]]] = 1;
ll x = ask(w);
if(x > def) b = md;
else a = md+1;
}
s = unodes[a];
a = 0, b = int(vnodes.size())-1;
while(a < b){
int md = (a+b)/2;
vector<int> w = wv;
for(int i = 0; i <= md; i++) if(pv[vnodes[i]] != -1) w[pv[vnodes[i]]] = 1;
ll x = ask(w);
if(x > def) b = md;
else a = md+1;
}
t = vnodes[a];
answer(s, t);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
380 KB |
Output is correct |
2 |
Correct |
8 ms |
1360 KB |
Output is correct |
3 |
Correct |
80 ms |
10212 KB |
Output is correct |
4 |
Correct |
102 ms |
10208 KB |
Output is correct |
5 |
Correct |
118 ms |
10212 KB |
Output is correct |
6 |
Correct |
86 ms |
10200 KB |
Output is correct |
7 |
Correct |
82 ms |
10204 KB |
Output is correct |
8 |
Correct |
78 ms |
10212 KB |
Output is correct |
9 |
Correct |
75 ms |
10212 KB |
Output is correct |
10 |
Correct |
81 ms |
10204 KB |
Output is correct |
11 |
Correct |
126 ms |
9812 KB |
Output is correct |
12 |
Correct |
112 ms |
9648 KB |
Output is correct |
13 |
Correct |
102 ms |
9692 KB |
Output is correct |
14 |
Correct |
86 ms |
9596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
1272 KB |
Output is correct |
2 |
Correct |
14 ms |
2396 KB |
Output is correct |
3 |
Correct |
26 ms |
3364 KB |
Output is correct |
4 |
Correct |
84 ms |
9724 KB |
Output is correct |
5 |
Correct |
65 ms |
9724 KB |
Output is correct |
6 |
Correct |
62 ms |
9624 KB |
Output is correct |
7 |
Correct |
72 ms |
9616 KB |
Output is correct |
8 |
Correct |
101 ms |
9720 KB |
Output is correct |
9 |
Correct |
63 ms |
9632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
11 ms |
1360 KB |
Output is correct |
3 |
Correct |
55 ms |
8108 KB |
Output is correct |
4 |
Correct |
96 ms |
10208 KB |
Output is correct |
5 |
Correct |
119 ms |
10208 KB |
Output is correct |
6 |
Correct |
99 ms |
10228 KB |
Output is correct |
7 |
Correct |
99 ms |
10208 KB |
Output is correct |
8 |
Correct |
104 ms |
10184 KB |
Output is correct |
9 |
Correct |
82 ms |
10180 KB |
Output is correct |
10 |
Correct |
106 ms |
10204 KB |
Output is correct |
11 |
Correct |
104 ms |
9616 KB |
Output is correct |
12 |
Correct |
104 ms |
9564 KB |
Output is correct |
13 |
Correct |
107 ms |
9796 KB |
Output is correct |
14 |
Correct |
88 ms |
9692 KB |
Output is correct |
15 |
Correct |
71 ms |
10200 KB |
Output is correct |
16 |
Correct |
90 ms |
10220 KB |
Output is correct |
17 |
Correct |
95 ms |
9608 KB |
Output is correct |
18 |
Correct |
119 ms |
9760 KB |
Output is correct |
19 |
Correct |
92 ms |
10212 KB |
Output is correct |
20 |
Correct |
114 ms |
9592 KB |
Output is correct |
21 |
Correct |
99 ms |
10908 KB |
Output is correct |
22 |
Correct |
98 ms |
10808 KB |
Output is correct |
23 |
Correct |
110 ms |
10692 KB |
Output is correct |
24 |
Correct |
75 ms |
10484 KB |
Output is correct |
25 |
Correct |
110 ms |
9700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
1392 KB |
Output is correct |
2 |
Correct |
26 ms |
1492 KB |
Output is correct |
3 |
Correct |
127 ms |
10572 KB |
Output is correct |
4 |
Correct |
100 ms |
11252 KB |
Output is correct |
5 |
Correct |
176 ms |
12180 KB |
Output is correct |
6 |
Correct |
124 ms |
12288 KB |
Output is correct |
7 |
Correct |
147 ms |
12248 KB |
Output is correct |
8 |
Correct |
140 ms |
12280 KB |
Output is correct |
9 |
Correct |
147 ms |
8320 KB |
Output is correct |
10 |
Correct |
127 ms |
8540 KB |
Output is correct |
11 |
Correct |
100 ms |
9632 KB |
Output is correct |
12 |
Correct |
116 ms |
11144 KB |
Output is correct |
13 |
Correct |
121 ms |
11844 KB |
Output is correct |
14 |
Correct |
126 ms |
12328 KB |
Output is correct |
15 |
Correct |
132 ms |
12296 KB |
Output is correct |
16 |
Correct |
160 ms |
9440 KB |
Output is correct |
17 |
Correct |
71 ms |
10576 KB |
Output is correct |
18 |
Correct |
82 ms |
10776 KB |
Output is correct |
19 |
Correct |
100 ms |
10684 KB |
Output is correct |
20 |
Correct |
103 ms |
10792 KB |
Output is correct |
21 |
Correct |
172 ms |
12224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
1408 KB |
Output is correct |
2 |
Correct |
10 ms |
1492 KB |
Output is correct |
3 |
Correct |
158 ms |
10740 KB |
Output is correct |
4 |
Correct |
115 ms |
10864 KB |
Output is correct |
5 |
Correct |
104 ms |
11184 KB |
Output is correct |
6 |
Correct |
121 ms |
12464 KB |
Output is correct |
7 |
Correct |
126 ms |
10620 KB |
Output is correct |
8 |
Correct |
104 ms |
10784 KB |
Output is correct |
9 |
Correct |
151 ms |
11280 KB |
Output is correct |
10 |
Correct |
178 ms |
12484 KB |
Output is correct |
11 |
Correct |
119 ms |
12428 KB |
Output is correct |
12 |
Correct |
122 ms |
12280 KB |
Output is correct |
13 |
Correct |
124 ms |
9440 KB |
Output is correct |
14 |
Correct |
84 ms |
8540 KB |
Output is correct |
15 |
Correct |
142 ms |
9444 KB |
Output is correct |
16 |
Correct |
125 ms |
8560 KB |
Output is correct |
17 |
Correct |
108 ms |
9436 KB |
Output is correct |
18 |
Correct |
87 ms |
8628 KB |
Output is correct |
19 |
Correct |
176 ms |
11236 KB |
Output is correct |
20 |
Correct |
115 ms |
11792 KB |
Output is correct |
21 |
Correct |
172 ms |
12352 KB |
Output is correct |
22 |
Correct |
160 ms |
12304 KB |
Output is correct |
23 |
Correct |
130 ms |
12432 KB |
Output is correct |
24 |
Correct |
124 ms |
12316 KB |
Output is correct |
25 |
Correct |
136 ms |
12252 KB |
Output is correct |
26 |
Correct |
157 ms |
12320 KB |
Output is correct |
27 |
Correct |
78 ms |
10732 KB |
Output is correct |
28 |
Correct |
114 ms |
10620 KB |
Output is correct |
29 |
Correct |
82 ms |
11008 KB |
Output is correct |
30 |
Correct |
79 ms |
10752 KB |
Output is correct |
31 |
Correct |
85 ms |
10676 KB |
Output is correct |
32 |
Correct |
99 ms |
10604 KB |
Output is correct |
33 |
Correct |
93 ms |
10856 KB |
Output is correct |
34 |
Correct |
98 ms |
10716 KB |
Output is correct |
35 |
Correct |
84 ms |
10668 KB |
Output is correct |
36 |
Correct |
102 ms |
10580 KB |
Output is correct |
37 |
Correct |
93 ms |
10796 KB |
Output is correct |
38 |
Correct |
106 ms |
10772 KB |
Output is correct |
39 |
Correct |
165 ms |
12384 KB |
Output is correct |
40 |
Correct |
175 ms |
12276 KB |
Output is correct |
41 |
Correct |
118 ms |
12136 KB |
Output is correct |
42 |
Correct |
144 ms |
12364 KB |
Output is correct |