Test instructions
An undirected graph with n points is given, in which there are main edges of n-1 and these main edges constitute a tree, and there are other sides of M, to cut off a main side of the original image and a number of other edges that make the graph disconnected.
Note that even if you only cut off the main edges to make the original image disconnected, you still need to cut off another side to be a solution.
Solution
Consider one of the properties of the original image: There are only two scenarios where the original image is not connected:
1. The main side is the original bridge
2. The two connected blocks connected by the primary and additional edges are connected to only these two edges
It is clear that each of the 1 generated schemes have m species, and each 2 produces only one solution.
Considering that the main side of the original image forms a tree and that only the main side can be a bridge, a property is thought of:
If you mark the path of each additional edge to the tree, then the edges that are not marked are the original ones (note that the bridge must be the primary side), and only the edges marked once must correspond to the only one 2.
So consider using the tree chain, plus the interval modification function, and finally query the number of times each edge is marked, then the unmarked edge is the original bridge, Ans+=m (because this edge and any combination of additional edges are a scheme); Only the edges marked once correspond to the only one 2,ans++ The edge marked more than 1 times is clearly not a scheme (because the two connected blocks on either side of it are connected to at least two edges, and any one of them cannot be disconnected by cutting off any of them).
By the way, the implementation of the interval modification of the single-point query function can use a Difference score group, so that a single interval modified O (1), the last one to query O (n), and then a single path to modify O (logn), tree profile pretreatment o (n), the total complexity of O (N+MLOGN), compared to the line segment tree LOG2N), the total complexity O (nlogn+mlog2n) is much faster, and the code is shorter, the constants are smaller, and the memory is saved.
PostScript
Listen to the question person (Magic_sheep) said there are several solutions, but this 鶸 slag only think of one, the other has not thought out, in this worship God Ben.
The bridge and the connecting block of the solution sounds like a graph theory, in fact, this tree-based approach is from the graph theory of the bridge and connected block development, but the use of the nature of the tree, tree-based implementation. Therefore, I think it is possible to solve the problem by combining and reconstructing the algorithm of bridge and double connected component.
It's very hard to think about the subject, but the code implementation is very easy (My code just 80+ the line). It makes a lot of sense to do this problem more.
COGS 2434 Dark Chain lock