#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define all(x) x.begin(), x.end()
using namespace std;
template <class X, class Y> bool minimize(X &a, Y b) {
if (a > b) return a = b, true;
return false;
}
template <class X, class Y> bool maximize(X &a, Y b) {
if (a < b) return a = b, true;
return false;
}
const int N = 2e6 + 7;
int n, m, t;
int dp[N];
vector<int> adj[N];
void dfs(int u, int p) {
if ((int) adj[u].size() == 1) {
return;
}
int F = 0, S = 0;
for (int v: adj[u]) if (v != p) {
dfs(v, u);
if (F < dp[v]) {
S = F;
F = dp[v];
} else {
maximize(S, dp[v]);
}
}
dp[u] = (int) adj[u].size() + S - 1;
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> t >> m;
for (int i = 1; i < n; i ++) {
int u, v; cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(m, t);
cout << dp[m];
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
30 ms |
47188 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
290 ms |
80444 KB |
Output is correct |
2 |
Correct |
312 ms |
83284 KB |
Output is correct |
3 |
Correct |
752 ms |
89748 KB |
Output is correct |
4 |
Correct |
397 ms |
71564 KB |
Output is correct |
5 |
Correct |
774 ms |
89708 KB |
Output is correct |
6 |
Correct |
787 ms |
89828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
30 ms |
47188 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
30 ms |
47188 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |