#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N = (int)1e6 + 100;
vector<int> T[N];
int trap;
int mouse;
int dfs(int u, int par, int cum){
vector<int> lis;
int deg = 0;
for(auto x : T[u]){
if(x==par) continue;
deg ++ ;
}
for(auto x : T[u]){
if(x==par) continue;
lis.push_back(dfs(x,u,cum+deg));
}
sort(lis.begin(), lis.end());
if(lis.size() <= 1){
return cum;
}
return lis[(int)lis.size() - 2];
}
int main(){
fastIO;
int n;
cin >> n;
cin >> trap >> mouse;
int u, v;
for(int i = 1; i < n; i ++ ){
cin >> u >> v;
T[u].push_back(v);
T[v].push_back(u);
}
cout << dfs(mouse,trap,0);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
23788 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
377 ms |
67880 KB |
Output is correct |
2 |
Correct |
343 ms |
64236 KB |
Output is correct |
3 |
Correct |
892 ms |
69228 KB |
Output is correct |
4 |
Incorrect |
409 ms |
46444 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
23788 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
23788 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |