Study Notes --prufer sequence

prufer sequence What is?

Baidu Encyclopedia says:

Prufer unrooted trees number of columns is a number of columns. In Combinatorial Mathematics, Prufer by having a number of columns for the number of vertices of the tree through the conversion to the number of columns, the number of points of n tree Prufer conversion to the column length is n-2. It can be calculated by a simple iterative method.


Transformation and unrooted tree

1. unrooted trees turn sequence prufer

Repeating the steps until only two points:

1 degree is found and the minimum number of nodes x, it is connected to the node is added \ (Prufer \) sequence once, then delete x

2.prufer sequence turn unrooted trees

Ready to set a point ( \ (1,2,3,4 {, ...., n-} \) )

Repeating the steps until the \ (Prufer \) sequence is empty:

Found there and point set in the current sequence is not present Prufer smallest one of v, with the current \ (Prufer \) a first sequence number \ (U \) , the \ (U \) and \ ( v \) even side, and then delete \ (u \) and \ (v \)

nature

  • The sequence length is \ (2-n-\) (nonsense)

  • A degree of \ (D_i \) point appears in the sequence \ (d_i-1 \) times (the degree of its \ (D_i \) becomes 1 were added to the sequence of (d_i-1 \) \ times)

  • \ (Prufer \) sequence unrooted trees correspond , this means that the number of seek unrooted trees is equivalent to finding \ (Prufer \) number sequence, the living tree problem (error) for converting the sequence problem


topic

1. [HNOI2004] tree count

Meaning of the questions: Given a tree in the degree of each node \ (d_i \) number, seek to meet the conditions of the tree, the answer is not more than \ (1e17 \)

Practice: nature understood from the above, each point will \ (Prufer \) appears in the sequence \ (d_i-1 \) times, the number of trees required is equivalent to finding the sequence number, then it becomes a multiset permutation problem, apply the formula can be obtained:

\(ans = \frac{(n-2)!}{\prod_{i=1}^n(d_i-1)!}\)

This problem requires some additional Laid sentence, such as \ (\ Sigma (-D_i. 1) \ n-NEQ-2 \) , or only one point, or \ (D_i = 0 \) , is not repeated herein (Although it has been finished

Since the calculation process may explode \ (longlongs \) , requires high-precision division or decomposed chemical control of the quality factor Save

2. [HNOI2008] obviously troubles

Meaning of the questions: As above, if a given \ (D_i = -1 \) , it means that this point is not limited degree

Practice: Let \ (CNT \) represents \ (neq-1 \ d_i \ ) the number of points, \ (SUM \) represents \ (\ Sigma (-D_i. 1) \) (provided that the \ (d_i \ neq- 1 \) ), and these points so as to satisfy the above question (assuming \ (d_ {1-cnt} \) is \ (\ neq -1 \) points):

\(p = \frac{sum!}{\prod_{i=1}^{cnt}(d_i-1)!}\)

Since the total (n-2 \) \ positions that \ (SUM \) location method has selected \ (C_ {n-2} ^ {sum} \) species

The remaining \ ((n-cnt) \ ) points may rest \ (\ (n-2- sum)) position appear any number of times, that is \ ((n-cnt) ^ {n-sum -2} \) choices

So have:

\ (Ans = C_ {n-2} ^ {I} * P * (n-cut) ^ {n-to-2} \)

Simplification can be obtained:

\ (ANS = \ frac {(n-2)!} {(N-2-sum)! \ Prod (di-1)!} * (N-cnt) ^ {n-sum-2} \)

You can do, use a high-precision multiply-add approach with the first question

Guess you like

Origin www.cnblogs.com/Chtholly/p/11402692.html