G - Diverge and Converge Editorial
by
noya2
This problem deals with the process of exchanging one edge at a time between two trees with the same set of vertices, eventually replacing the entire set of edges. We will prove that there exists a way in which the two graphs always remain trees during this process.
We will use induction on the number of vertices \(N\). The case for \(N=1\) is trivial.
Now, consider the multigraph \(G = (V, E_A \cup E_B)\) formed by merging the edge sets of two trees \(A = (V, E_A)\) and \(B = (V, E_B)\). By the spanning nature of trees \(A\) and \(B\) and the fact that the average degree of each vertex in \(G\) is less than \(4\), there exists a vertex \(c\) in \(G\) whose degree is either \(2\) or \(3\).
First, let’s handle the case where the degree of \(c\) in \(G\) is \(2\). In this case, \(c\) is connected by exactly one edge in each of \(A\) and \(B\). By exchanging these edges and applying the inductive hypothesis to the graphs obtained by removing \(c\) from \(A\) and \(B\), we can obtain a sequence of operations that satisfies the conditions.
Next, let’s consider the case where the degree of \(c\) in \(G\) is \(3\). Without loss of generality, assume that the degree of \(c\) in \(A\) is \(1\) and in \(B\) is \(2\), and that \(A\) contains the edge \(xc\) and \(B\) contains the edges \(yc\) and \(zc\). By removing \(c\) from \(A\) and \(B\) and adding the edge \(yz\) to \(B\), the resulting graphs \(A'\) and \(B'\) are trees on \(N-1\) vertices with the same set of vertices. By the inductive hypothesis, we can obtain a sequence of operations that satisfies the conditions. Now, pay attention to the moment when the edge \(yz\) of \(B'\) is exchanged in this sequence. When the edge \(yz\) is removed from \(B'\), its vertex set splits into two connected components. Without loss of generality, assume that \(x\) and \(y\) are in the same component. Instead of exchanging the edge \(e\) of \(A'\) and the edge \(yz\) of \(B'\), we can first exchange the edge \(xc\) of \(A\) and the edge \(yc\) of \(B\), followed by exchanging the edge \(e\) of \(A\) and the edge \(zc\) of \(B\). By performing these exchanges in this order, we obtain a sequence of operations that satisfies the conditions for \(A\) and \(B\).
By tracing through this proof, it is possible to actually construct the sequence of operations in \(O(N^2)\) time.
posted:
last update:
