#include <bits/stdc++.h>
#include "highway.h"
using namespace std;
#define int long long
vector<vector<int>> graph;
int normal;
map<pair<int, int>, int> edgeToIndex;
int bsEdges(int M) {
int l=0; int r = M-1;
while (l<r) {
vector<signed> a(M, 0);
int m = (l + r) / 2;
for (int i=l; i<=m; i++) {
a[i] = 1;
}
if (ask(a) != normal) {
r = m;
}
else {
l = m+1;
}
}
return l;
}
vector<int> side;
vector<bool> visited;
void sideDFS(int v) {
if (visited[v]) return;
visited[v] = 1;
side[v] = 1;
for (int i: graph[v]) {
sideDFS(i);
}
}
vector<pair<int, int>> cand;
void findLevel(int v, int t, int l, int p) {
if (visited[v]) return;
visited[v] = 1;
if (l == t) {
cand.push_back({v, p});
}
for (int i: graph[v]) {
findLevel(i, t, l+1, v);
}
}
int BS2(vector<pair<int, int>> edges, int M) {
int l = 0; int r = edges.size()-1;
while (l<r) {
vector<signed> a(M, 0);
int m = (l + r) / 2;
for (int i=l; i<=m; i++) {
a[edgeToIndex[{min(edges[i].first, edges[i].second), max(edges[i].first, edges[i].second)}]] = 1;
}
if (ask(a) != normal) {
r = m;
}
else {
l = m+1;
}
}
return edges[l].first;
}
void find_pair(signed N, std::vector<signed> U, std::vector<signed> V, signed A, signed B) {
int M = U.size();
assert(M == N-1);
vector<signed> a(M, 0);
normal = ask(a);
vector<pair<int, int>> edges;
graph.clear();
graph.resize(N);
edgeToIndex.clear();
for (int i=0; i<M; i++) {
edges.push_back({min(U[i], V[i]), max(U[i], V[i])});
graph[U[i]].push_back(V[i]);
graph[V[i]].push_back(U[i]);
edgeToIndex[{min(U[i], V[i]), max(U[i], V[i])}] = i;
}
pair<int, int> edgeOnPath = edges[bsEdges(M)];
side.assign(N, 0);
visited.assign(N, 0);
visited[edgeOnPath.second] = 1;
sideDFS(edgeOnPath.first);
pair<int, int> length;
{
vector<signed> askk(M, 0);
for (int i=0; i<M; i++) {
if (side[edges[i].first] && side[edges[i].second]) askk[i] = 1;
}
int tmp = ask(askk);
length.first = ((tmp-normal)/(B-A));
length.second = ((normal - (length.first * A)) / A) -1;
}
visited.assign(N, 0);
cand.clear();
visited[edgeOnPath.second] = 1;
findLevel(edgeOnPath.first, length.first, 0, -1);
int start = BS2(cand, M);
visited.assign(N, 0);
cand.clear();
visited[edgeOnPath.first] = 1;
findLevel(edgeOnPath.second, length.second, 0, -1);
int end = BS2(cand, M);
answer(min(start, end), max(start, end));
}
# |
결과 |
실행 시간 |
메모리 |
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 |
208 KB |
Output is correct |
7 |
Correct |
0 ms |
208 KB |
Output is correct |
8 |
Correct |
1 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 |
300 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
464 KB |
Output is correct |
2 |
Correct |
13 ms |
1948 KB |
Output is correct |
3 |
Correct |
160 ms |
16076 KB |
Output is correct |
4 |
Correct |
161 ms |
16036 KB |
Output is correct |
5 |
Correct |
163 ms |
16036 KB |
Output is correct |
6 |
Correct |
154 ms |
15788 KB |
Output is correct |
7 |
Correct |
200 ms |
16064 KB |
Output is correct |
8 |
Correct |
210 ms |
15660 KB |
Output is correct |
9 |
Correct |
203 ms |
15684 KB |
Output is correct |
10 |
Correct |
174 ms |
16072 KB |
Output is correct |
11 |
Correct |
182 ms |
16392 KB |
Output is correct |
12 |
Correct |
154 ms |
17320 KB |
Output is correct |
13 |
Correct |
165 ms |
16812 KB |
Output is correct |
14 |
Correct |
212 ms |
16896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
2540 KB |
Output is correct |
2 |
Correct |
25 ms |
4800 KB |
Output is correct |
3 |
Correct |
46 ms |
7288 KB |
Output is correct |
4 |
Correct |
95 ms |
19380 KB |
Output is correct |
5 |
Correct |
104 ms |
19520 KB |
Output is correct |
6 |
Correct |
128 ms |
20720 KB |
Output is correct |
7 |
Correct |
108 ms |
21660 KB |
Output is correct |
8 |
Correct |
137 ms |
20008 KB |
Output is correct |
9 |
Correct |
106 ms |
20264 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
464 KB |
Output is correct |
2 |
Correct |
17 ms |
2032 KB |
Output is correct |
3 |
Correct |
110 ms |
12212 KB |
Output is correct |
4 |
Correct |
209 ms |
15916 KB |
Output is correct |
5 |
Correct |
231 ms |
15584 KB |
Output is correct |
6 |
Correct |
188 ms |
15564 KB |
Output is correct |
7 |
Correct |
184 ms |
15588 KB |
Output is correct |
8 |
Correct |
223 ms |
15572 KB |
Output is correct |
9 |
Correct |
180 ms |
16040 KB |
Output is correct |
10 |
Correct |
203 ms |
16076 KB |
Output is correct |
11 |
Correct |
212 ms |
16432 KB |
Output is correct |
12 |
Correct |
162 ms |
17324 KB |
Output is correct |
13 |
Correct |
173 ms |
17060 KB |
Output is correct |
14 |
Correct |
227 ms |
16928 KB |
Output is correct |
15 |
Correct |
206 ms |
15640 KB |
Output is correct |
16 |
Correct |
168 ms |
15576 KB |
Output is correct |
17 |
Correct |
166 ms |
16676 KB |
Output is correct |
18 |
Correct |
208 ms |
17028 KB |
Output is correct |
19 |
Correct |
226 ms |
15688 KB |
Output is correct |
20 |
Correct |
158 ms |
17708 KB |
Output is correct |
21 |
Correct |
236 ms |
18608 KB |
Output is correct |
22 |
Correct |
234 ms |
18688 KB |
Output is correct |
23 |
Correct |
212 ms |
17556 KB |
Output is correct |
24 |
Correct |
245 ms |
17548 KB |
Output is correct |
25 |
Correct |
192 ms |
21444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
8 ms |
720 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
9 ms |
756 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |