//
// Created by 42kangaroo on 25/08/2024.
//
#include "bits/stdc++.h"
#include "highway.h"
using ll = long long;
using namespace std;
struct Ed {
int to, i;
};
using g_t = vector<vector<Ed>>;
struct BfsVal {
int to, i, d;
};
bool operator<(const BfsVal &l, const BfsVal &r) {
return l.d < r.d;
}
void addDfs(int n, int p, g_t &g, vector<int> &dis, vector<BfsVal> &out) {
for (auto e: g[n]) {
if (e.to == p) continue;
out.push_back({e.to, e.i, dis[e.to]});
addDfs(e.to, n, g, dis, out);
}
}
void wDfs(int n, int p, g_t &g, vector<int> &w) {
for (auto e: g[n]) {
if (e.to == p) continue;
w[e.i] = 0;
wDfs(e.to, n, g, w);
}
}
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
vector<int> w(U.size(), 0);
ll le = ask(w) / (ll) A;
vector<bool> vis(N, false);
g_t g(N);
for (int i = 0; i < U.size(); ++i) {
g[U[i]].push_back({V[i], i});
g[V[i]].push_back({U[i], i});
}
int l = 0, r = U.size();
while (l + 1 < r) {
int m = (l + r) / 2;
std::fill(w.begin(), w.end(), 1);
for (int i = 0; i < m; ++i) {
w[i] = 0;
}
if (ask(w) > le * A) r = m;
else l = m;
}
vector<int> dis(N, -1);
g_t gBfs(N);
queue<BfsVal> q;
q.push({U[l], -1, 0});
q.push({V[l], -1, 0});
while (!q.empty()) {
auto bfV = q.front();
q.pop();
if (dis[bfV.to] != -1) continue;
if (bfV.i >= 0) {
gBfs[U[bfV.i]].push_back({V[bfV.i], bfV.i});
gBfs[V[bfV.i]].push_back({U[bfV.i], bfV.i});
}
dis[bfV.to] = bfV.d;
for (auto e: g[bfV.to]) {
q.push({e.to, e.i, bfV.d + 1});
}
}
vector<BfsVal> out;
int x = U[l], y = V[l];
addDfs(U[l], V[l], gBfs, dis, out);
std::sort(out.begin(), out.end());
int ll = 0, rr = out.size();
while (ll + 1 < rr) {
int m = (ll + rr) / 2;
std::fill(w.begin(), w.end(), 1);
for (int i = 0; i < m; ++i) {
w[out[i].i] = 0;
}
wDfs(V[l], U[l], gBfs, w);
if (ask(w) > A * le) ll = m;
else rr = m;
}
if (!out.empty())
x = out[ll].to;
out.clear();
addDfs(V[l], U[l], gBfs, dis, out);
std::sort(out.begin(), out.end());
ll = 0, rr = out.size();
while (ll + 1 < rr) {
int m = (ll + rr) / 2;
std::fill(w.begin(), w.end(), 1);
for (int i = 0; i < m; ++i) {
w[out[i].i] = 0;
}
wDfs(U[l], V[l], gBfs, w);
if (ask(w) > A * le) ll = m;
else rr = m;
}
if (!out.empty())
y = out[ll].to;
answer(x, y);
}
Compilation message
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:44:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for (int i = 0; i < U.size(); ++i) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
600 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
3196 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
600 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
2136 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
2136 KB |
Output is incorrect: {s, t} is wrong. |
2 |
Halted |
0 ms |
0 KB |
- |