#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector,Ofast")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=1e6+5;
const ld pi=acos(-1);
const ll INF=(1LL<<60);
#define SQ(i) ((i)*(i))
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(_a) (ll)_a.size()
ll n,t,s,dp[N],x,y;
vector<ll> v[N];
void DFS(ll nd,ll pa){
ll ma=0,mb=0;
for(auto i:v[nd]){
if(i==pa)continue;
DFS(i,nd);
if(dp[i]>=ma)mb=ma,ma=dp[i];
else if(dp[i]>=mb)mb=dp[i];
}
dp[nd]=mb+SZ(v[nd])-1;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>t>>s;
REP(i,n-1)cin>>x>>y,v[x].pb(y),v[y].pb(x);
DFS(t,0);
cout<<dp[s]<<"\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
16 ms |
23788 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
340 ms |
84224 KB |
Output is correct |
2 |
Correct |
310 ms |
78188 KB |
Output is correct |
3 |
Correct |
813 ms |
82348 KB |
Output is correct |
4 |
Correct |
372 ms |
52844 KB |
Output is correct |
5 |
Correct |
807 ms |
82412 KB |
Output is correct |
6 |
Correct |
802 ms |
82284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
16 ms |
23788 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
16 ms |
23788 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |