Under construction

Still being built. Things may change

Cactus Transformation

Time limit3sMemory limit2048 MB

Summary
Decide whether one cactus graph can be turned into another by repeatedly removing an edge and adding a new one, at most 15000 times, and print the moves.
Level

Hard9 of 10

Topics
Graph, Tree, DFS, Implementation
Solved
No attempts yet

Problem

In the university, Caroline started to learn about cactus graphs. Her teacher wanted to check whether the students really understood the definition of a cactus, so he gave them the following home assignment.

You are given two cactuses with the same number of vertices and edges. Determine whether the first cactus can be transformed into the second one using the following two-step operation at most 15 00015\,000 times:

  • Pick an arbitrary edge from the first cactus and remove it. After this step, the graph does not have to be a cactus.
  • Add an arbitrary non-existing edge to the first graph so that the graph becomes a cactus.

Each operation consists of both steps, so you must perform both steps every time.

It is guaranteed that if the transformation is possible, it can be done using at most 15 00015\,000 operations.

A cactus is a connected undirected graph in which every edge lies on at most one simple cycle. A cactus has no multiple edges and no loops.

Two cactuses are called the same if for every pair of vertices vv and uu (1≤v<u≤n1 \le v < u \le n), either both cactuses have the edge (v,u)(v, u) or neither does.

Input

The first line contains two integers nn and mm (3≤n≤10003 \le n \le 1000, n−1≤m≤⌊3(n−1)2⌋n - 1 \le m \le \lfloor \frac{3(n - 1)}{2} \rfloor), the number of vertices and edges in each cactus. Each of the next 2⋅m2 \cdot m lines contains two integers uu and vv (1≤u≠v≤n1 \le u \ne v \le n), an edge. The first mm lines describe the first cactus, and the next mm lines describe the second cactus.

Output

If the first cactus cannot be transformed into the second one, print a single line with "NO".

Otherwise, print "YES" on the first line. On the second line, print the number of operations cc (0≤c≤15 0000 \le c \le 15\,000). Each of the following cc lines contains four integers w1w_1, w2w_2, w3w_3, w4w_4 (1≤wi≤n1 \le w_i \le n). The vertices w1w_1 and w2w_2 are the endpoints of the removed edge, and w3w_3 and w4w_4 are the endpoints of the added edge.

Examples2

  1. Example 1

    Input
    5 5
    1 2
    3 1
    2 4
    3 4
    4 5
    1 2
    3 2
    3 1
    4 1
    3 5
    
    Expected output
    YES
    3
    3 4 2 3
    5 4 3 5
    2 4 1 4
    
  2. Example 2

    Input
    5 6
    1 2
    2 3
    1 3
    4 3
    3 5
    5 4
    1 2
    2 4
    4 1
    4 3
    3 5
    4 5
    
    Expected output
    NO