16-- digital conversion training camp 501-511NOIP

Portal: QAQQAQ

 

Meaning of the questions: If the divisor and a number x (not including itself, the same below) is smaller than itself , then x can be turned into its divisors; if for some y> x and y is the number about x, then x can become y. For example, 4 may be changed to become 3,1 7. All digital conversion defined in no more than n a positive integer range, constantly seeking digital conversion without converting the number of steps is repeated up to the number that appears.

 

Ideas: YY what, if $ x $ can be changed to $ y $, then $ y $ can certainly becomes $ x $, so we can transform each other for a spot to build a undirected edges, because a point where most of each and a value smaller than its connected edge point, it appears unlikely ring (which may be manually YY proof)

So we ran to one of the longest chain in the acyclic "forest" in

 

Actually the code is the root :( run is not precise enough in diameter, with the longest chain operator better DP)

#include<bits/stdc++.h>
using namespace std;
 
vector<int> v[50005];
int d[50005];
 
void dfs(int u,int f,int depth)
{
    d[u]=depth;
    for(int i=0;i<(int)v[u].size();i++)
    {
        if(v[u][i]==f) continue;
        dfs(v[u][i],u,depth+1);
    }
}
 
void init(int n)
{
    for(int i=2;i<=n;i++)
    {
        int sum=0;
        for(int j=1;j*j<=i;j++)
        {
            if(i%j==0)
            {
                sum+=j;
                if(j*j!=i&&j!=1) sum+=i/j;
            }
        }
        if(sum<i)
        {
            v[sum].push_back(i);
            v[i].push_back(sum);
        }
    }
//  for(int i=1;i<=n;i++)
//  {
//      cout<<i<<":";
//      for(int j=0;j<v[i].size();j++) cout<<v[i][j]<<" ";
//      cout<<endl;
//  }
}
 
int main()
{
    int n; cin>>n;
    init(n);
    dfs(1,-1,0);
    int s=-1,maxn=-1;
    for(int i=1;i<=n;i++)
    {
        if(maxn<d[i])
        {
            maxn=d[i];
            s=i;
        }
    }
    dfs(s,-1,0);
    for(int i=1;i<=n;i++)
    {
        if(maxn<d[i]) maxn=d[i];
    }
    cout<<maxn<<endl;
    return 0;
}
View Code

 

Guess you like

Origin www.cnblogs.com/Forever-666/p/11279755.html