#include <bits/stdc++.h>
std::vector<std::vector<int>> adj;
int send_message(int N, int i, int Pi) {
if (adj.empty()) {
adj.resize(N);
}
adj[i].push_back(Pi);
adj[Pi].push_back(i);
if (i == N - 1) {
std::vector<int> d(N);
auto dfs = [&](auto &&self, int u, int p) -> void {
for (int &i : adj[u]) {
if (i != p) {
d[i] = d[u] + 1;
self(self, i, u);
}
}
};
dfs(dfs, 0, -1);
int it = std::max_element(d.begin(), d.end()) - d.begin() + 1;
return it;
} else {
return 0;
}
}
std::pair<int, int> longest_path(std::vector<int> S) {
adj.clear();
return {0, S.back() - 1};
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |