# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
463567 | vanic | Mousetrap (CEOI17_mousetrap) | C++14 | 833 ms | 73388 KiB |
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 <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn=1e6+5;
vector < int > ms[maxn];
int dp[maxn];
void dfs(int x, int prosl){
dp[x]=ms[x].size()-1;
int maksi=0, drugi=0;
for(int i=0; i<(int)ms[x].size(); i++){
if(ms[x][i]!=prosl){
dfs(ms[x][i], x);
if(dp[ms[x][i]]>maksi){
drugi=maksi;
maksi=dp[ms[x][i]];
}
else if(dp[ms[x][i]]>drugi){
drugi=dp[ms[x][i]];
}
}
}
dp[x]+=drugi;
}
int main(){
int n, t, m;
scanf("%d%d%d", &n, &t, &m);
t--;
m--;
int a, b;
for(int i=0; i<n-1; i++){
scanf("%d%d", &a, &b);
a--;
b--;
ms[a].push_back(b);
ms[b].push_back(a);
}
if(n==1){
printf("0\n");
return 0;
}
dfs(t, t);
printf("%d\n", dp[m]);
return 0;
}
Compilation message (stderr)
# | 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... |