#include <bits/stdc++.h>
using namespace std;
int m;
long long a, b;
long long ask(const std::vector<int> &w);
long long get(const vector<int>& busy) {
vector<int> q(m, 0);
for (int i : busy) q[i] = 1;
return ask(q);
}
void answer(int s, int t);
void rec(vector<int> now, vector<vector<int>>& full, int path_le) {
if (!now.size()) return;
long long here = get(now);
if (here == 1ll*path_le*a) return;
if (here == 1ll*now.size()*b + 1ll*(path_le-now.size())*a) {
full.push_back(now);
return;
}
// random_shuffle(now.begin(), now.end());
vector<int> left, right;
for (int i = 0; i < now.size()/2; ++i) {
left.push_back(now[i]);
}
for (int i = now.size()/2; i < now.size(); ++i) {
right.push_back(now[i]);
}
rec(left, full, path_le);
rec(right, full, path_le);
}
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A_, int B_) {
a = A_;
b = B_;
m = U.size();
vector<int> v;
map<pair<int, int>, int> ind;
vector<vector<int>> gr(N);
for (int i = 0; i < U.size(); ++i) {
ind[{U[i], V[i]}] = ind[{V[i], U[i]}] = i;
gr[U[i]].push_back(V[i]);
gr[V[i]].push_back(U[i]);
}
vector<int> tour;
vector<bool> vis(N, false);
v.clear();
srand(time(0));
auto get_tour = [&] (auto&& self, int X, int pr) -> void {
tour.push_back(X);
vis[X] = true;
// random_shuffle(gr[X].begin(), gr[X].end());
for (int u : gr[X]) if (!vis[u]) {
self(self, u, X);
}
if (pr != -1)
v.push_back(ind[{pr, X}]);
};
get_tour(get_tour, 0, -1);
vector<vector<int>> full;
long long path_le = get(v) / b;
rec(v, full, path_le);
map<int, int> c;
for (auto& x : full) {
for (int j : x) {
c[U[j]]++;
c[V[j]]++;
}
}
vector<int> vs;
for (auto [x, y] : c) {
if (y == 1) vs.push_back(x);
}
answer(vs[0], vs[1]);
}
Compilation message
highway.cpp: In function 'void rec(std::vector<int>, std::vector<std::vector<int> >&, int)':
highway.cpp:19:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'long long unsigned int' [-Wsign-compare]
19 | if (here == 1ll*now.size()*b + 1ll*(path_le-now.size())*a) {
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
highway.cpp:25:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for (int i = 0; i < now.size()/2; ++i) {
| ~~^~~~~~~~~~~~~~
highway.cpp:28:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | for (int i = now.size()/2; i < now.size(); ++i) {
| ~~^~~~~~~~~~~~
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:42:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for (int i = 0; i < U.size(); ++i) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
3672 KB |
Output is correct |
2 |
Correct |
23 ms |
6992 KB |
Output is correct |
3 |
Correct |
35 ms |
10280 KB |
Output is correct |
4 |
Incorrect |
137 ms |
30624 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
16 ms |
3104 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
17 ms |
2904 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |