#B3904. Graph Transformation Sequence
Graph Transformation Sequence
Graph Transformation Sequence
We are given two undirected simple graphs with the same vertex set: an initial graph and a target graph . The target graph is assumed to be constructed by the following transformation procedure from :
- Initialize an empty graph on vertices (i.e. no edges).
- While there are at least two vertices in , choose two vertices and from that have equal degree (i.e. $$deg_S(u)=deg_S(v)$$). Then, add the edge to and remove vertex (together with all edges incident to ) from .
- When only one vertex remains in , the constructed graph is obtained.
Moreover, one may iterate this procedure: starting from , we perform one transformation , from which a further transformation (and so on) may be done. In this problem, you are given and (both on vertices) and your task is to find at least one sequence of transformations (with at least and at most transformation steps) such that
where in each transformation the chosen edges (the pairs selected in that procedure) exactly form the constructed tree. The input is guaranteed to have a solution. If there are multiple valid answers, output any one of them.
inputFormat
The first line contains a single integer (the number of vertices). Then follows the description of the graph : • An integer representing the number of edges in , followed by lines each containing two integers and (1-based) that denote an edge between vertices and . Next is the description of the graph : • An integer representing the number of edges in , followed by lines each containing two integers and that denote an edge between vertices and .
outputFormat
Output a valid transformation sequence which consists of exactly transformation procedures (with ). For each transformation procedure, output an integer on a separate line (which should equal , the number of operations in that procedure), followed by lines each containing two integers and representing the pair chosen in that operation. The overall first line of the output should be the integer . (Note: In our solutions we use , i.e. a single transformation.)
sample
3
3
1 2
1 3
2 3
2
1 2
2 3
1
2
1 2
3 2
</p>