#ifdef NYAOWO
#include "grader.cpp"
#endif
#include "highway.h"
#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define eb emplace_back
using namespace std;
using LL = long long;
using pii = pair<int, int>;
const int MAXN = 90010;
vector<pii> adj[MAXN]; // index, eid
int dep[MAXN];
int eid[MAXN];
int typ[MAXN];
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
cerr << A << " " << B << "\n";
int M = U.size();
LL dist = ask(vector<int>(M, 0));
assert(dist % A == 0);
auto out = [&](int x) { cerr << "(" << U[x] << ", " << V[x] << ")\n" << flush; };
For(i, 0, M - 1) {
adj[U[i]].eb(V[i], i);
adj[V[i]].eb(U[i], i);
}
int hi = M - 1, lo = -1;
while(hi - lo > 1) {
int mi = lo + (hi - lo) / 2;
vector<int> w(M, 0);
fill(w.begin(), w.begin() + mi + 1, 1);
LL d2 = ask(w);
if(d2 > dist) hi = mi;
else lo = mi;
}
int a = U[hi], b = V[hi];
cerr << "key edge: " << hi << " "; out(hi);
// build bfs tree
memset(typ, -1, sizeof(typ));
queue<int> que;
dep[a] = 1; dep[b] = 1;
eid[a] = eid[b] = hi;
typ[a] = 0; typ[b] = 1;
que.emplace(a); que.emplace(b);
vector<int> ed[2];
vector<int> w0(M, 1);
while(!que.empty()) {
int cur = que.front(); que.pop();
w0[eid[cur]] = 0;
ed[typ[cur]].eb(eid[cur]);
for(auto &e:adj[cur]) if(typ[e.F] == -1 && e.S >= hi) {
dep[e.F] = dep[cur] + 1;
eid[e.F] = e.S;
typ[e.F] = typ[cur];
que.emplace(e.F);
}
}
// cerr << "bfs tree #0\n"; for(auto &id:ed[0]) out(id);
// cerr << "bfs tree #1\n"; for(auto &id:ed[1]) out(id);
int m = sz(ed[0]);
hi = m; lo = -1;
while(hi - lo > 1) {
int mi = lo + (hi - lo) / 2;
vector<int> w(all(w0));
For(i, mi, m - 1) w[ed[0][i]] = 1;
auto d2 = ask(w);
if(d2 == dist) hi = mi;
else lo = mi;
}
dep[b] = 0;
int id = ed[0][lo];
int x0 = U[id];
if(dep[V[id]] > dep[U[id]]) x0 = V[id];
cerr << "x0: " << x0 << "\n";
dep[b] = 1;
m = sz(ed[1]);
hi = m; lo = -1;
while(hi - lo > 1) {
int mi = lo + (hi - lo) / 2;
vector<int> w(all(w0));
For(i, mi, m - 1) w[ed[1][i]] = 1;
auto d2 = ask(w);
if(d2 == dist) hi = mi;
else lo = mi;
}
dep[a] = 0;
id = ed[1][lo];
int x1 = U[id];
if(dep[V[id]] > dep[U[id]]) x1 = V[id];
cerr << "x1: " << x1 << "\n";
dep[a] = 1;
answer(x0, x1);
// for (int j = 0; j < 50; ++j) {
// std::vector<int> w(M);
// for (int i = 0; i < M; ++i) {
// w[i] = 0;
// }
// long long toll = ask(w);
// }
// answer(0, N - 1);
}
/*
4 4 1 3 1 3
0 1
0 2
0 3
1 2
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2768 KB |
Output is correct |
2 |
Correct |
2 ms |
2768 KB |
Output is correct |
3 |
Correct |
1 ms |
2768 KB |
Output is correct |
4 |
Correct |
2 ms |
2664 KB |
Output is correct |
5 |
Correct |
2 ms |
2768 KB |
Output is correct |
6 |
Correct |
3 ms |
2768 KB |
Output is correct |
7 |
Correct |
2 ms |
2768 KB |
Output is correct |
8 |
Correct |
2 ms |
2676 KB |
Output is correct |
9 |
Correct |
2 ms |
2680 KB |
Output is correct |
10 |
Correct |
2 ms |
2768 KB |
Output is correct |
11 |
Correct |
2 ms |
2768 KB |
Output is correct |
12 |
Correct |
2 ms |
2768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2768 KB |
Output is correct |
2 |
Correct |
19 ms |
3408 KB |
Output is correct |
3 |
Correct |
132 ms |
9400 KB |
Output is correct |
4 |
Correct |
114 ms |
9380 KB |
Output is correct |
5 |
Correct |
135 ms |
9472 KB |
Output is correct |
6 |
Correct |
97 ms |
9408 KB |
Output is correct |
7 |
Correct |
136 ms |
9400 KB |
Output is correct |
8 |
Correct |
151 ms |
9564 KB |
Output is correct |
9 |
Correct |
122 ms |
9496 KB |
Output is correct |
10 |
Correct |
115 ms |
9548 KB |
Output is correct |
11 |
Correct |
86 ms |
8564 KB |
Output is correct |
12 |
Correct |
137 ms |
9028 KB |
Output is correct |
13 |
Correct |
106 ms |
8920 KB |
Output is correct |
14 |
Correct |
122 ms |
9128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
3408 KB |
Output is correct |
2 |
Correct |
19 ms |
4124 KB |
Output is correct |
3 |
Correct |
29 ms |
4472 KB |
Output is correct |
4 |
Correct |
74 ms |
8732 KB |
Output is correct |
5 |
Correct |
75 ms |
8648 KB |
Output is correct |
6 |
Correct |
114 ms |
8732 KB |
Output is correct |
7 |
Correct |
71 ms |
7804 KB |
Output is correct |
8 |
Correct |
103 ms |
8816 KB |
Output is correct |
9 |
Correct |
79 ms |
8132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2768 KB |
Output is correct |
2 |
Correct |
18 ms |
3384 KB |
Output is correct |
3 |
Correct |
82 ms |
8104 KB |
Output is correct |
4 |
Correct |
122 ms |
9464 KB |
Output is correct |
5 |
Correct |
97 ms |
8976 KB |
Output is correct |
6 |
Correct |
114 ms |
8960 KB |
Output is correct |
7 |
Correct |
122 ms |
9384 KB |
Output is correct |
8 |
Correct |
104 ms |
9020 KB |
Output is correct |
9 |
Correct |
111 ms |
9480 KB |
Output is correct |
10 |
Correct |
121 ms |
9452 KB |
Output is correct |
11 |
Correct |
153 ms |
8904 KB |
Output is correct |
12 |
Correct |
109 ms |
9096 KB |
Output is correct |
13 |
Correct |
127 ms |
9016 KB |
Output is correct |
14 |
Correct |
92 ms |
8568 KB |
Output is correct |
15 |
Correct |
102 ms |
9004 KB |
Output is correct |
16 |
Correct |
116 ms |
8376 KB |
Output is correct |
17 |
Correct |
164 ms |
8880 KB |
Output is correct |
18 |
Correct |
143 ms |
8944 KB |
Output is correct |
19 |
Correct |
78 ms |
8596 KB |
Output is correct |
20 |
Correct |
120 ms |
8428 KB |
Output is correct |
21 |
Correct |
91 ms |
9836 KB |
Output is correct |
22 |
Correct |
116 ms |
9508 KB |
Output is correct |
23 |
Correct |
124 ms |
9912 KB |
Output is correct |
24 |
Correct |
88 ms |
9820 KB |
Output is correct |
25 |
Correct |
98 ms |
9132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
3508 KB |
Output is correct |
2 |
Correct |
19 ms |
3556 KB |
Output is correct |
3 |
Correct |
151 ms |
9792 KB |
Output is correct |
4 |
Correct |
163 ms |
10540 KB |
Output is correct |
5 |
Correct |
158 ms |
11404 KB |
Output is correct |
6 |
Correct |
180 ms |
11728 KB |
Output is correct |
7 |
Correct |
195 ms |
11924 KB |
Output is correct |
8 |
Correct |
136 ms |
11244 KB |
Output is correct |
9 |
Correct |
162 ms |
9056 KB |
Output is correct |
10 |
Correct |
174 ms |
9832 KB |
Output is correct |
11 |
Correct |
124 ms |
10112 KB |
Output is correct |
12 |
Correct |
153 ms |
11204 KB |
Output is correct |
13 |
Correct |
155 ms |
11404 KB |
Output is correct |
14 |
Correct |
183 ms |
11508 KB |
Output is correct |
15 |
Correct |
181 ms |
11372 KB |
Output is correct |
16 |
Correct |
182 ms |
10276 KB |
Output is correct |
17 |
Correct |
119 ms |
10068 KB |
Output is correct |
18 |
Correct |
87 ms |
9692 KB |
Output is correct |
19 |
Correct |
99 ms |
10096 KB |
Output is correct |
20 |
Correct |
114 ms |
9772 KB |
Output is correct |
21 |
Correct |
253 ms |
11296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
3536 KB |
Output is correct |
2 |
Correct |
16 ms |
3660 KB |
Output is correct |
3 |
Correct |
154 ms |
9876 KB |
Output is correct |
4 |
Correct |
167 ms |
10028 KB |
Output is correct |
5 |
Correct |
145 ms |
10552 KB |
Output is correct |
6 |
Correct |
173 ms |
11412 KB |
Output is correct |
7 |
Correct |
124 ms |
9868 KB |
Output is correct |
8 |
Correct |
129 ms |
10084 KB |
Output is correct |
9 |
Correct |
126 ms |
10408 KB |
Output is correct |
10 |
Correct |
185 ms |
11548 KB |
Output is correct |
11 |
Correct |
168 ms |
11616 KB |
Output is correct |
12 |
Correct |
179 ms |
11580 KB |
Output is correct |
13 |
Correct |
111 ms |
9760 KB |
Output is correct |
14 |
Correct |
162 ms |
9536 KB |
Output is correct |
15 |
Correct |
178 ms |
10336 KB |
Output is correct |
16 |
Correct |
108 ms |
9788 KB |
Output is correct |
17 |
Correct |
168 ms |
10116 KB |
Output is correct |
18 |
Correct |
126 ms |
9812 KB |
Output is correct |
19 |
Correct |
192 ms |
11136 KB |
Output is correct |
20 |
Correct |
198 ms |
11228 KB |
Output is correct |
21 |
Correct |
179 ms |
11600 KB |
Output is correct |
22 |
Correct |
159 ms |
11740 KB |
Output is correct |
23 |
Correct |
199 ms |
11824 KB |
Output is correct |
24 |
Correct |
156 ms |
11592 KB |
Output is correct |
25 |
Correct |
153 ms |
11324 KB |
Output is correct |
26 |
Correct |
166 ms |
11496 KB |
Output is correct |
27 |
Correct |
98 ms |
9864 KB |
Output is correct |
28 |
Correct |
96 ms |
9916 KB |
Output is correct |
29 |
Correct |
93 ms |
10320 KB |
Output is correct |
30 |
Correct |
101 ms |
10076 KB |
Output is correct |
31 |
Correct |
110 ms |
9988 KB |
Output is correct |
32 |
Correct |
98 ms |
9948 KB |
Output is correct |
33 |
Correct |
137 ms |
10400 KB |
Output is correct |
34 |
Correct |
136 ms |
9980 KB |
Output is correct |
35 |
Correct |
112 ms |
10056 KB |
Output is correct |
36 |
Correct |
123 ms |
9956 KB |
Output is correct |
37 |
Correct |
107 ms |
10156 KB |
Output is correct |
38 |
Correct |
92 ms |
10068 KB |
Output is correct |
39 |
Correct |
210 ms |
11500 KB |
Output is correct |
40 |
Correct |
199 ms |
11420 KB |
Output is correct |
41 |
Correct |
184 ms |
11296 KB |
Output is correct |
42 |
Correct |
207 ms |
11628 KB |
Output is correct |