#include<bits/stdc++.h>
using namespace std;
#define fori(i, l, r) for(int i = (int) (l); i <= (int) (r); i++)
#define ford(i, r, l) for(int i = (int) (r); i >= (int) (l); i--)
#define ii pair<int, int>
#define fi first
#define se second
#define vi vector<int>
#define eb emplace_back
#define em emplace
#define sp ' '
#define endl '\n'
//#define int long long
#define ld long double
const int maxn = 2e5 + 5;
int n;
vi g[maxn];
int m, t;
int dp[maxn];
void dfs_solve(int u, int p) {
if(g[u].size() == 1) {
dp[u] = 0;
}
else {
int mx = 0, mx2 = 0;
for(int v: g[u]) {
if(v == p) continue;
dfs_solve(v, u);
if(dp[v] > mx) {
mx2 = mx;
mx = dp[v];
}
else if(dp[v] > mx2) {
mx2 = dp[v];
}
}
dp[u] = g[u].size() + mx2 - 1;
}
}
signed main() {
// freopen("oneway.inp", "r", stdin);
// freopen("oneway.out", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> t >> m;
fori(i, 1, n - 1) {
int u, v; cin >> u >> v;
g[u].eb(v);
g[v].eb(u);
}
if(count(begin(g[t]), end(g[t]), m)) {
dfs_solve(m, t);
cout << dp[m];
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
58 ms |
22564 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |