AGC018F - Two Trees

The meaning of problems

There are two sections of n points are rooted tree, you need to construct a sequence \ (X_1, X_2, ..., X_n \) . Such that for each node of each tree, so if all its descendants (including itself) as \ (A_1, A_2, ..., a_k \) , then there are \ (abs (X_ {a_1} + X_ + ????? + A_2} {X_ {a_k}) =. 1 \) . Determining whether feasible, if available output a viable solution.

practice

\ (-. 1 \ equiv. 1 (MOD ~ 2) \) , which tells us the \ (a_i \) assigned to \ (\ {- 1,0,1 \} \)
may be determined according to the number of parity point son sex

Clearly get parity of the points two trees are the same as possible to the line
to have a stronger conclusion: the same parity will be able to construct a viable option

This configuration: all singularities in both trees correspond to the position even side, the establishment of a virtual point even two trees to the root node, retaining the original side; run Euler tour for a path, we set the direction (in itself a path there is no direction); if there is a singular point of the first run to the second tree tree, is set to \ (- 1 \) , otherwise it is set to \ (1 \) , so even point is set to \ (0 \)

Is defined as an edge between the lateral side of the fork two trees
will split into a number of Euler directed ring.
Class 1 represents the node to ring his son away from the current, and then from his son back to the current point
class 2 ring away from the current node representing his son, from father side back to the current point (the reverse is the same)
3 class representation from the current loop while walking to his father node fork or transverse edges, and back down the other of these two
class 4 represents a ring away from the current node to a son, back from the edge of this lateral cross point (the reverse is the same)
so resolved the benefits can be found in a ring on each point and is \ (0 \) , then divide the parity point briefly discuss it. Do not expand here in detail, can be seen here

Guess you like

Origin www.cnblogs.com/Grice/p/12374585.html