【DFS+思维】 GYM101620J Justified Jungle

http://codeforces.com/gym/101620/attachments

 

#include 
using namespace std;
set  s;
int head[1000005],to[2000005],nxt[2000005],Size[1000005],num[1000005];
int tot,n;

void addedge(int u,int v)
{
    to[++tot]=v;
    nxt[tot]=head[u];
    head[u]=tot;
}

void dfs(int u,int fa)
{
    Size[u]=1;
    for(int i=head[u];i!=-1;i=nxt[i])
    {
        int v=to[i];
        if(v==fa) continue;
        dfs(v,u);
        Size[u]+=Size[v];
    }
    num[Size[u]]++;
}

int ok(int x)
{
    int ans=0;
    for(int i=x;i<=n;i+=x)
    {
        ans+=num[i];
    }
    return ans;
}

int main()
{
    memset(head,-1,sizeof(head));
    scanf("%d",&n);
    tot=0;
    for(int i=1;i::iterator it = s.begin(); it != s.end(); ++it)
    {
        int p = *it;
        printf("%d ",p);
    }
    printf("\n");
    return 0;
}

 

你可能感兴趣的:(思维题,dfs)