Ex - We Love Forest Editorial by GidroOttenok3797


\(f(S)\) in the official editorial, the number of trees whose vertex set is \(S\subseteq V\), can be found without Kirchhoff’s theorem. Specifically, it can be calculated by

\[ f(S) = \begin{cases} 1 & (\text{if }|S| \leq 1) \\ \displaystyle \frac{1}{2(|S|-1)} \sum_{T \subset S} f(T) f(S \setminus T) \mathcal{E}(T, S \setminus T) & (\text{otherwise}). \end{cases} \]

Here, for two disjoint sets \(U\) and \(W\) of vertices, \(\mathcal{E}(U, W)\) denotes the number of edges connecting a vertex of \(U\) and a vertex of \(W\), which can be calculated by

\[ \mathcal{E}(U, W) = e(U \cup W) - e(U) - e(W) \]

where \(e(U)\) denotes the number of edges connecting two of the vertex set \(U\).

By precomputing \(e(U)\) for every vertex set \(U\) in a total of \(O(N^2 2^N)\) time, \(f(S)\) can be obtained for every vertex set \(S\) in a total of \(O(3^N)\) time.

posted:
last update: