Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***************************************************************************
- * ####### # *
- * # # # ###### # # # # #### # # # # # *
- * # # # # # # ## # # # # # # # *
- * # ###### ##### # # # # # #### ###### # # # *
- * # # # # ####### # # # # # # # # # *
- * # # # # # # # ## # # # # # # # *
- * # # # ###### # # # # #### # # #### ###### *
- ***************************************************************************/
- #include<bits/stdc++.h>
- #define ll long long
- #define pb push_back
- #define endl '\n'
- #define pii pair<ll int,ll int>
- #define vi vector<ll int>
- #define all(a) (a).begin(),(a).end()
- #define F first
- #define S second
- #define sz(x) (ll int)x.size()
- #define hell 1000000007
- #define rep(i,a,b) for(ll int i=a;i<b;i++)
- #define lbnd lower_bound
- #define ubnd upper_bound
- #define bs binary_search
- using namespace std;
- #define N 100005
- ll a[N];
- vi ad[N];
- bool vis[N]={0};
- vi timer;
- ll tin[N];
- ll tout[N];
- vi tree[4*N];
- ll div1[N];
- void dfs(ll node)
- {
- timer.pb(node);
- tin[node]=timer.size()-1;
- vis[node]=1;
- for(auto i:ad[node])
- if(!vis[i])
- dfs(i);
- tout[node]=timer.size();
- }
- void build(ll node,ll start,ll end)
- {
- if(start==end)
- {
- tree[node].pb(a[timer[start]]);
- return;
- }
- ll mid=(start+end)/2;
- build(2*node,start,mid);
- build(2*node+1,mid+1,end);
- merge(tree[2*node].begin(), tree[2*node].end(),tree[2*node+1].begin(), tree[2*node+1].end(),back_inserter(tree[node]));
- return;
- }
- ll query(ll node,ll start,ll end,ll l,ll r,ll val)
- {
- if(r<start || l>end || start>end || l>r)
- return 0;
- if(start>=l && end<=r)
- {
- ll p=lower_bound(tree[node].begin(), tree[node].end(),val)-tree[node].begin();
- return p;
- }
- ll mid=(start+end)/2;
- return(query(2*node,start,mid,l,r,val)+query(2*node+1,mid+1,end,l,r,val));
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- int TESTS=1;
- // cin>>TESTS;
- while(TESTS--)
- {
- ll n,x,y;
- cin>>n;
- rep(i,1,N)
- {
- for(ll j=i;j<N;j+=i)
- div1[j]++;
- }
- timer.pb(0);
- rep(i,1,n+1)
- cin>>a[i];
- rep(i,0,n-1)
- {
- cin>>x>>y;
- ad[x].pb(y);
- ad[y].pb(x);
- }
- dfs(1);
- build(1,1,n);
- ll max=0,val;
- rep(i,1,n+1)
- {
- ll sum=query(1,1,n,tin[i]+1,tout[i]-1,a[i]);
- if(sum!=0)
- {
- val=div1[sum];
- if(val>max)
- max=val;
- }
- }
- cout<<max;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement