#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, t, m;
cin >> N >> t >> m;
t--, m--;
vector<vector<int>> adj(N);
for (int i = 0; i < N - 1; i++) {
int x, y;
cin >> x >> y;
x--, y--;
if (minmax(x, y) == minmax(m, t)) {
continue;
}
adj[x].push_back(y);
adj[y].push_back(x);
}
vector<int> f(N);
auto dfs = [&](auto dfs, int x, int p) -> void {
vector<int> s;
for (int y : adj[x]) {
if (y == p) {
continue;
}
dfs(dfs, y, x);
s.push_back(f[y]);
}
sort(s.rbegin(), s.rend());
if (s.empty()) {
return;
}
if (s.size() == 1) {
f[x] = 1;
return;
}
f[x] = s[1] + s.size();
};
dfs(dfs, m, -1);
cout << f[m] << "\n";
return 6/22;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
235 ms |
72404 KB |
Output is correct |
2 |
Correct |
210 ms |
65076 KB |
Output is correct |
3 |
Correct |
713 ms |
73296 KB |
Output is correct |
4 |
Correct |
274 ms |
36660 KB |
Output is correct |
5 |
Correct |
676 ms |
73292 KB |
Output is correct |
6 |
Correct |
713 ms |
73332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |