제출 #742964

#제출 시각아이디문제언어결과실행 시간메모리
742964zaneyuCat Exercise (JOI23_ho_t4)C++14
31 / 100
2077 ms24740 KiB
#include<bits/stdc++.h> using namespace std; using ll=long long; using ld=long double; using pii=pair<int,int>; #define f first #define s second #define pb push_back #define REP(i,n) for(int i=0;i<n;i++) #define REP1(i,n) for(int i=1;i<=n;i++) #define FILL(n,x) memset(n,x,sizeof(n)) #define ALL(_a) _a.begin(),_a.end() #define sz(x) (int)x.size() #define SORT_UNIQUE(c) (sort(c.begin(),c.end()),c.resize(distance(c.begin(),unique(c.begin(),c.end())))) const ll maxn=5e5+5; const ll maxlg=__lg(maxn)+2; const ll INF64=4e18; const int INF=0x3f3f3f3f; const int MOD=1e9+7; const ld PI=acos(-1); const ld eps=1e-4; #define lowb(x) x&(-x) #define MNTO(x,y) x=min(x,(__typeof__(x))y) #define MXTO(x,y) x=max(x,(__typeof__(x))y) int cur; vector<int> g[maxn]; int ans=0; int dp[maxn]; vector<pii> v; int arr[maxn]; int pp; int mx=0; void dfs(int u,int p,int d){ if(arr[u]>cur) return; if(pp==-1 or arr[u]>arr[pp]) pp=u,mx=dp[u]+d; for(int x:g[u]){ if(x==p) continue; dfs(x,u,d+1); } } int main(){ int n; cin>>n; REP(i,n){ int x; cin>>x; --x; v.pb({x,i}); arr[i]=x; } REP(i,n-1){ int a,b; cin>>a>>b; --a,--b; g[a].pb(b),g[b].pb(a); } sort(ALL(v)); for(auto x:v){ cur=x.f; for(int a:g[x.s]){ pp=-1; dfs(a,x.s,1); if(pp!=-1) MXTO(dp[x.s],mx); } //cout<<dp[x.s]<<' '; } cout<<dp[v.back().s]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...