This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |