제출 #1194946

#제출 시각아이디문제언어결과실행 시간메모리
1194946loomMousetrap (CEOI17_mousetrap)C++20
0 / 100
179 ms70868 KiB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define inf 5e18
#define nl '\n'

const int N = 1e6+1;
vector<int> g[N];
int dp[N];

void dfs(int v, int p){
   vector<int> w;
   for(int ch : g[v]){
      if(ch == p) continue;

      dfs(ch, v);
      w.push_back(dp[ch]);
   }
   sort(w.rbegin(), w.rend());

   dp[v] = (w.size() >= 2 ? w[1] : 0) + w.size();
}

inline void solve(){
   int n, t, m;
   cin>>n>>t>>m;
   for(int i=1; i<n; i++){
      int a, b;
      cin>>a>>b;
      g[a].push_back(b);
      g[b].push_back(a);
   }

   dfs(t, 0);
   cout<<dp[m]+1;
}

signed main(){
   ios_base::sync_with_stdio(0);
   cin.tie(NULL);cout.tie(NULL);

   int t = 1;
   //cin>>t;
   while(t--) solve();

   return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...