https://codeforces.com/contest/1405/problem/D
我是zz,看错题了,其实就两种可能
1.开局直接被抓住 disA >= dis(a,b)
2.逃跑,但是如何跑呢?我们发现,db >= 2*da + 1就能跑的了,因为db小的化迟早会被抓住,放风筝就好了,看了题解发现自己真是个sb
#include<iostream> #include<cstring> #include<vector> using namespace std; typedef long long ll; const int maxn = 2e5+11; vector<int>G[maxn]; int list[maxn]; int cns[maxn]; void add(int x,int y){ G[x].push_back(y); } int flag = 0; int vis[maxn]; int dp[maxn]; int dis; int dfs(int x,int fa){ int cns = 0; for(int i=0;i<G[x].size();i++){ int p = G[x][i]; if(p == fa) continue; dfs(p,x); dp[x] = max(dp[x] ,dp[p] + 1); cns = max(dp[p],cns); } int f = 0; dis = max(dis,cns+2); for(int i=0;i<G[x].size();i++){ int p = G[x][i]; if(p == fa) continue; if(cns == dp[p] && f) dis = max(dis,dp[p] + cns + 3); if(cns > dp[p]) dis = max(dis,dp[p] + cns + 3); if(cns == dp[p]) f = 1; } return 0; } int dep; int n,a,b,aa,bb; int dfs(int x,int fa,int d){ if(x == b){ dep = d; } for(int i=0;i<G[x].size();i++){ int p = G[x][i]; if(p == fa) continue; dfs(p,x,d+1); } return 0; } int main(){ int t; cin>>t; while(t--){ cin>>n>>a>>b>>aa>>bb; for(int i=0;i<=n;i++){ G[i].clear(); vis[i] = 0; dp[i] = 0; } flag = 0; int x,y; for(int i=1;i<n;i++){ cin>>x>>y; add(x,y); add(y,x); } dis = 0; dfs(1,-1); dfs(a,-1,0); if(dep <= aa){ cout<<"Alice "; } else{ dis--; if(dis >= 2*aa + 1 && bb >= 2*aa+1){ cout<<"Bob "; } else{ cout<<"Alice "; } } } return 0; }