Describe
Three kinds of animals a eat B, B eat C, C eat a.
1, A, b for the same kind
2, A, b means a eats B.
Judging the number of false lies
Analysis
- Noip saw before, not at that time, now it is a bit abstract to understand.
- Combination of weighted values and check set
- Can determine the relationship of X, Y's find to the same ancestor.
- PA[X] is the ancestor of X, R[x] is the distance from X to the ancestor, there are three kinds, 0, 1, 2. 0 The expression and ancestor homogeneous, 1 means can eat ancestors, 2 means to be eaten. R[find (x)] must be 0 I verified it with an assert.
- To find the first record of the X current ancestor px, when x and PX initially determine the relationship r[px] must be 0. The value of r[px] after the recursive find (PX) is the distance from PX to the current ancestor, and X and PX are now the same ancestor, so the distance from X to the original PX is the distance from the PX to the current ancestor.
- When merging X, y, first px = find (x), py = Find (y). For example, to set PA[PX] as a py, the PY will not change, consider the PX rank how to change. If the merge requires X, y similar, then x to the py distance should be equal to the r[y], then r[x] + r[px] = = R[y], so r[px] = R[y]-r[x]. This way, after the path is compressed, the new r[x] is equal to r[y].
codevs-1074-food chain-and check