#include "highway.h"
#include <bits/stdc++.h>
#ifdef LOCAL
#include "template/debug.hpp"
#else
#define dbg(...) ;
#define timer(...) ;
#endif
std::vector<int> bfs(int s, const std::vector<std::vector<std::pair<int, int>>>& adj) {
int N = adj.size();
std::vector<int> d(N, -1);
std::queue<int> q;
q.push(s);
d[s] = 0;
while (q.size()) {
int u = q.front();
q.pop();
for (auto [v, id] : adj[u]) {
if (d[v] == -1) {
d[v] = d[u] + 1;
q.push(v);
}
}
}
return d;
}
std::vector<std::pair<int, int>> build_tree(int s, const std::vector<std::vector<std::pair<int, int>>>& adj, const std::vector<int>& d1, const std::vector<int>& d2) {
int N = adj.size();
std::vector<std::pair<int, int>> tree;
std::vector<int> d(N, -1);
std::queue<int> q;
q.push(s);
d[s] = 0;
while (q.size()) {
int u = q.front();
q.pop();
for (auto [v, id] : adj[u]) {
if (d1[v] < d2[v] && d[v] == -1) {
tree.emplace_back(v, id);
d[v] = d[u] + 1;
q.push(v);
}
}
}
return tree;
}
int solve(int s, int M, long long sd, const std::vector<std::pair<int, int>>& trees, const std::vector<std::pair<int, int>>& treet) {
int ans = -1, lb = 0, rb = trees.size() - 1;
while (lb <= rb) {
int m = (lb + rb) / 2;
std::vector<int> w(M, 0);
for (int j = m; j < (int) trees.size(); j++) {
w[trees[j].second] = 1;
}
auto res = ask(w);
if (res != sd) {
ans = m;
lb = m + 1;
} else {
rb = m - 1;
}
}
if (ans == -1) return s;
return trees[ans].first;
}
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
std::vector<std::vector<std::pair<int, int>>> adj(N);
int M = U.size();
for (int i = 0; i < M; i++) {
adj[U[i]].emplace_back(V[i], i);
adj[V[i]].emplace_back(U[i], i);
}
auto shortest_distance = ask(std::vector<int>(M, 0));
int first_in_path = M - 1;
int lb = 0, rb = M - 2;
while (lb <= rb) {
int m = (lb + rb) / 2;
auto nice = std::vector<int>(M, 0);
std::fill(nice.begin(), nice.begin() + m + 1, 1);
auto ans = ask(nice);
if (ans != shortest_distance) {
first_in_path = m;
rb = m - 1;
} else {
lb = m + 1;
}
}
auto a = U[first_in_path];
auto b = V[first_in_path];
auto d1 = bfs(a, adj);
auto d2 = bfs(b, adj);
auto treea = build_tree(a, adj, d1, d2);
auto treeb = build_tree(b, adj, d2, d1);
auto ff = solve(a, M, shortest_distance, treea, treeb);
auto ee = solve(b, M, shortest_distance, treeb, treea);
answer(ff, ee);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
696 KB |
Output is correct |
2 |
Correct |
1 ms |
448 KB |
Output is correct |
3 |
Correct |
0 ms |
452 KB |
Output is correct |
4 |
Correct |
1 ms |
440 KB |
Output is correct |
5 |
Correct |
0 ms |
444 KB |
Output is correct |
6 |
Correct |
1 ms |
448 KB |
Output is correct |
7 |
Correct |
0 ms |
444 KB |
Output is correct |
8 |
Correct |
0 ms |
440 KB |
Output is correct |
9 |
Correct |
1 ms |
444 KB |
Output is correct |
10 |
Correct |
0 ms |
448 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
764 KB |
Output is correct |
2 |
Correct |
14 ms |
1556 KB |
Output is correct |
3 |
Correct |
110 ms |
10180 KB |
Output is correct |
4 |
Correct |
113 ms |
9976 KB |
Output is correct |
5 |
Correct |
95 ms |
10100 KB |
Output is correct |
6 |
Correct |
92 ms |
9720 KB |
Output is correct |
7 |
Correct |
101 ms |
9972 KB |
Output is correct |
8 |
Correct |
115 ms |
9748 KB |
Output is correct |
9 |
Correct |
94 ms |
9720 KB |
Output is correct |
10 |
Correct |
82 ms |
9732 KB |
Output is correct |
11 |
Correct |
99 ms |
9288 KB |
Output is correct |
12 |
Correct |
86 ms |
9168 KB |
Output is correct |
13 |
Correct |
83 ms |
9300 KB |
Output is correct |
14 |
Correct |
91 ms |
9392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
1580 KB |
Output is correct |
2 |
Correct |
16 ms |
2360 KB |
Output is correct |
3 |
Correct |
32 ms |
3496 KB |
Output is correct |
4 |
Correct |
83 ms |
9156 KB |
Output is correct |
5 |
Correct |
86 ms |
9300 KB |
Output is correct |
6 |
Correct |
87 ms |
9424 KB |
Output is correct |
7 |
Correct |
65 ms |
9480 KB |
Output is correct |
8 |
Correct |
68 ms |
9304 KB |
Output is correct |
9 |
Correct |
77 ms |
9168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
516 KB |
Output is correct |
2 |
Correct |
11 ms |
1496 KB |
Output is correct |
3 |
Correct |
65 ms |
7756 KB |
Output is correct |
4 |
Correct |
96 ms |
9712 KB |
Output is correct |
5 |
Correct |
93 ms |
9744 KB |
Output is correct |
6 |
Correct |
72 ms |
9716 KB |
Output is correct |
7 |
Correct |
99 ms |
9728 KB |
Output is correct |
8 |
Correct |
97 ms |
9712 KB |
Output is correct |
9 |
Correct |
94 ms |
9816 KB |
Output is correct |
10 |
Correct |
88 ms |
9768 KB |
Output is correct |
11 |
Correct |
91 ms |
9504 KB |
Output is correct |
12 |
Correct |
98 ms |
9436 KB |
Output is correct |
13 |
Correct |
95 ms |
9352 KB |
Output is correct |
14 |
Correct |
95 ms |
9036 KB |
Output is correct |
15 |
Correct |
123 ms |
9908 KB |
Output is correct |
16 |
Correct |
93 ms |
9872 KB |
Output is correct |
17 |
Correct |
98 ms |
9224 KB |
Output is correct |
18 |
Correct |
86 ms |
9268 KB |
Output is correct |
19 |
Correct |
114 ms |
9732 KB |
Output is correct |
20 |
Correct |
125 ms |
9444 KB |
Output is correct |
21 |
Correct |
76 ms |
10376 KB |
Output is correct |
22 |
Correct |
75 ms |
10140 KB |
Output is correct |
23 |
Correct |
90 ms |
9672 KB |
Output is correct |
24 |
Correct |
85 ms |
9708 KB |
Output is correct |
25 |
Correct |
79 ms |
9280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
1588 KB |
Output is correct |
2 |
Correct |
12 ms |
1880 KB |
Output is correct |
3 |
Correct |
88 ms |
10064 KB |
Output is correct |
4 |
Correct |
162 ms |
10024 KB |
Output is correct |
5 |
Correct |
137 ms |
11708 KB |
Output is correct |
6 |
Correct |
134 ms |
11908 KB |
Output is correct |
7 |
Correct |
143 ms |
11504 KB |
Output is correct |
8 |
Incorrect |
120 ms |
11292 KB |
Output is incorrect: {s, t} is wrong. |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
1480 KB |
Output is correct |
2 |
Correct |
11 ms |
1572 KB |
Output is correct |
3 |
Correct |
108 ms |
10556 KB |
Output is correct |
4 |
Correct |
100 ms |
10036 KB |
Output is correct |
5 |
Correct |
158 ms |
10708 KB |
Output is correct |
6 |
Correct |
183 ms |
11016 KB |
Output is correct |
7 |
Correct |
124 ms |
10180 KB |
Output is correct |
8 |
Correct |
97 ms |
10312 KB |
Output is correct |
9 |
Incorrect |
124 ms |
10616 KB |
Output is incorrect: {s, t} is wrong. |
10 |
Halted |
0 ms |
0 KB |
- |