First of all, film a VFK leading global dynamic cactus cultivation technology ...
Then thank Time-machine seniors in the summer camp when told the Cactus DP.
And then I feel like I'm not listening. So come back to the paper and write an example code
This article is primarily about the basics of cactus (definition and nature, etc.)
———————————— line Cut is me >w< ——————————————— –
What is a cactus?
Cactus is a non-self-ring, a side of the most belong to a simple ring of undirected connected graph.
From the definition is not difficult to see the tree is actually a kind of cactus, that is to say the relationship between the concepts are:
The tree is a special kind of cactus, and Cactus is a special kind of undirected connected graph.
Take a look at the picture.
This is also a cactus ↓
So now we know how to differentiate between cactus and non-cactus.
We are all familiar with trees, so can we think of a cactus as a tree?
There's a way. The most annoying thing about a cactus is the ring. But we notice that there is no such thing as a ring on a cactus with a heavy edge on another ring, which is good, and we can think of the ring as something like a tree node, but this node contains much more information. (Note that just like, the nodes on the real tree are not the same!)
Modelled on the tree-related definitions, we can define the cactus on the Cactus node of the father and ring the father.
For a node on a cactus, it's possible that there are many possibilities for its father. If it is a simple path rather than a ring to the root path, then the father of this node is no different from the father of the usual tree node, Its father was the second point it experienced on the simple path to the root. Then if it is a ring adjacent to it on the root node path, it is the ring of the first edge that goes through the path to the root as its father.
For the ring, we define its father as the closest point to the root of a ring.
Relative then there was a son relationship.
For a node on a cactus, its son can obviously be a ring can be a normal node.
But for the son of the ring, all nodes other than the father of the ring are removed from the ring.
Unlike ordinary trees, the nodes on the ring have father nodes and Mother's Day points beyond the Father (why it is so confusing ...)
The Father node and the mother node of the node on the ring refer to the two points adjacent to the ring.
(Be sure not to confuse >_<)
How is the traversal of the cactus and the determination of the node information?
DFS is still started from the root node.
If we are going to access a node that has not been accessed before, then we can simply set the node's father as the current node. (from the definition of the father of the ring and the node it's obviously no problem)
So what if the node that we're going to visit has already been visited? Apparently there was a ring.
Then there are two things:
Now let's assume that the node we're accessing is X, and the node we're going to access is Y.
So if x is accessed earlier than Y for the first time, then this proves that Y's ring has been visited by us, so we don't need to deal with y any more alone.
If x is accessed more than Y for the first time, then X is on a ring with y as the father, and then loops through the ring to mark the Father node for Mother's Day.
At this point, the entire Cactus traversal completed, and all the nodes on the Cactus parent and child parents information has been processed out.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"Cactus Cactus" Cactus Basics Learning Notes