公式

F - Select and Split 解説 by evima


We assign distinct labels from \(1\) to \(N\) to the sets of integers written on the blackboard and have the label of \(S_0\) inherit to \(S_1\) during the operation. Since there are \(N!\) ways to assign labels, dividing the answer under this setting by \(N!\) will give the correct answer.

We consider counting the number of operations when the sets of integers \(T_1,T_2,\dots,T_N\) written on the blackboard after completing the series of operations are fixed, and add them all up to obtain the answer.

Counting the operations in reverse order yields the following problem:

Consider performing the following operation $N-1$ times for $N$ sets to obtain a single set.

  • Select a pair of integers $(a,b)$ with $a \leq A$ and $b > A$ such that $a$ and $b$ belong to different sets. Merge the sets containing $a$ and $b$.

Find the number of possible ways to perform the operation.

Here, we consider replacing the \(N\) sets with an \(N\)-vertex graph, replacing the merging of sets with the addition of edges, and managing the merging status with the connectivity of the graph. When thinking about operations under this rephrasing, what matters when choosing \(a\) and \(b\) is which sets they belonged to in the initial state. Let \(a_i\) and \(b_i\) respectively be the numbers of integers not greater than \(A\) and not less than \(A+1\) that belong to each set \(T_i\) in the initial state. Then, the problem can be restated as follows:

Consider performing the following operation $N-1$ times for a graph with $N$ vertices and zero edges to make it connected.

  • Select two disconnected vertices $i$ and $j$, and span an edge between vertices $i$ and $j$. Here, choose one from $a_ib_j+b_ia_j$ labels and assign it to the edge.

Find the number of possible ways to perform the operation.

This is a counting of spanning trees in a graph where there are \(a_ib_j+b_ia_j\) edges between vertices \(i\) and \(j\), and from the matrix tree theorem, the answer is the cofactor of the Laplacian

\[L=\mathrm{diag}(Ba_i+Ab_i) - \boldsymbol{a} \boldsymbol{b}^{T} - \boldsymbol{b} \boldsymbol{a}^{T}\]

multiplied by \((N-1)!\) (the \((N-1)!\) factor is for the order of adding edges). Here, \(\mathrm{diag}(Ba_i+Ab_i)\) is a matrix where the element at the \(i\)-th row and \(i\)-th column is \(Ba_i+Ab_i\) and the other diagonal components are zero, and \(\boldsymbol{a}\) and \(\boldsymbol{b}\) are column vectors where the element in the \(i\)-th row is \(a_i\) and \(b_i\), respectively.

Using the fact that the rank of \(\boldsymbol{a} \boldsymbol{b}^{T} + \boldsymbol{b} \boldsymbol{a}^{T}\) is \(2\) for this cofactor, the answer to this problem is

\[\displaystyle \left(\prod_{i=2}^{N} (Ba_i+Ab_i) \right) \left(1 - \sum_{i=2}^{N}\frac{2a_ib_i}{Ba_i+Ab_i} + \sum_{2 \leq i \neq j \leq N} \frac{a_ib_ia_jb_j}{(Ba_i+Ab_i)(Ba_j+Ab_j)} - \sum_{2 \leq i \neq j \leq N} \frac{a_i^2b_j^2}{(Ba_i+Ab_i)(Ba_i+Ab_j)}\right) \times (N-1)!\]

Now, we add up this value for all possible tuples of \(T_1,T_2,\dots,T_N\). Considering that \(a_i\) and \(b_i\) are respectively chosen from values not greater than \(A\) and not less than \(A+1\), the final answer is

\[\displaystyle \frac{A!B!}{N} \sum_{\sum a_i = A, \sum b_i = B} \frac{1}{a_1!b_1!} \left(\prod_{i=2}^{N} \frac{Ba_i+Ab_i}{a_i!b_i!} \right) \left(1 - \sum_{i=2}^{N}\frac{2a_ib_i}{Ba_i+Ab_i} + \sum_{2 \leq i \neq j \leq N} \frac{a_ib_ia_jb_j}{(Ba_i+Ab_i)(Ba_j+Ab_j)} - \sum_{2 \leq i \neq j \leq N} \frac{a_i^2b_j^2}{(Ba_i+Ab_i)(Ba_i+Ab_j)}\right) \]

Let’s calculate this value using formal power series. Using \(\sum_{}\frac{x^n}{n!}=e^x\), \(\sum_{}\frac{nx^n}{n!}=xe^x\), and \(\sum_{}\frac{n^2x^n}{n!}=(x^2+x)e^x\), this value is

\[\displaystyle \frac{A!B!}{N} [x^A y^B] (Bx+Ay)^{N-1}e^{N(x+y)}-2(N-1)xy(Bx+Ay)^{N-2} e^{N(x+y)}\]

\[+ (N-1)(N-2)x^2y^2 (Bx+Ay)^{N-3} e^{N(x+y)} - (N-1)(N-2)(x^2+x)(y^2+y)(Bx+Ay)^{N-3}e^{N(x+y)}\]

and ultimately we need to find \([x^{A-i}y^{B-j}](Bx+Ay)^{N-k}e^{N(x+y)}\) for a constant number of triples of \(i,j,k\). Under the precalculation of powers and factorials of \(N,A,B\), it can be calculated in \(O(N)\) time by expanding \((Bx+Ay)^{N-k}\) and computing the coefficient of \(e^{N(x+y)}\) for each term.

投稿日時:
最終更新: