# CF486D Valid Sets(CF486D Valid Sets)-其他

## CF486D Valid Sets(CF486D Valid Sets)

CF486D Valid Sets

$$O(n^2)$$ 。

Code

————————

CF486D Valid Sets

< strong > meaning of the question: < / strong >

Give a tree with point weight and find the number of connected subgraphs (points \ (n \ leqslant 2000 \)) that satisfy the range \ (\ leqslant K \).

< strong > solution: < / strong >

Due to the number of points \ (n \ leqslant 2000 \), we consider constructing an algorithm of \ (O (n ^ 2) \):

Traverse \ (I = 1.. n \) and take \ (I \) as the root \ (DP \).

Let \ (f_i \) represent the number of connected subgraphs containing range \ (\ leqslant K \) of point \ (I \). Then the transfer equation is: \ (f_ + = f_ \ cdot f_v \).

So how to traverse \ (f_v \) without repetition and leakage. We specify \ (a_i \) as the largest point weight in this set, so we only need to traverse the points with the point weight in \ (a_i – K \) ~ \ (a_i \). If \ (a_v = a_i \), we only traverse \ (V \) when numbering \ (I & gt; V \).

< strong > time complexity: < / strong >

$$O(n^2)$$ 。

Code