Subset Component - Hackerrank

I want to know how to approach Subset Component problem on Hackerrank efficiently,I know this can be done in Brute force manner but it will lead to TLE.

Problem Link : Subset Component

Please Provide a nice and simple Logical explanation… Thanks in Advance !!!

//