Under construction

Still being built. Things may change

Lepeze

Time limit2sMemory limit1024 MB

Summary
Under flip operations on a polygon triangulation, report the fewest flips needed to reach the fan at vertex x and how many shortest flip sequences exist.
Level

Hard9 of 10

Topics
Combinatorics, Tree, Dynamic programming
Solved
No attempts yet

Statement

Little Fran received a wooden frame in the shape of a regular polygon as a gift. The polygon has nn vertices, so he also received n(n−3)2\frac{n(n-3)}{2} wooden sticks, one for each possible diagonal. The vertices are labelled with integers from 1 to nn in counterclockwise order.

At the start, Fran placed n−3n-3 sticks inside the frame. Each stick touches two non-neighboring vertices, and no two sticks cross. In other words, the sticks form a triangulation.

Fran likes to change this configuration with an operation made of two steps:

  1. Remove a stick.
  2. Add a new stick so that the result is a new triangulation.

An operation is written as an ordered pair of unordered pairs ((a,b),(c,d))((a, b),(c, d)), which means Fran removed the stick touching vertices aa and bb and added a stick touching vertices cc and dd.

Fran sometimes asks how many operations it takes to turn the current triangulation into a fan triangulation at vertex xx, and how many ways there are to do it. A fan triangulation at vertex xx is one in which all diagonals share the common endpoint xx.

Let mm be the minimal number of operations. Let f1,f2,…,fmf_1, f_2, \dots, f_m and s1,s2,…,sms_1, s_2, \dots, s_m be two sequences of operations that reach the target in mm steps. The sequences are different if fi≠sif_i \ne s_i for some index ii. Count these sequences modulo 109+710^9 + 7.

Input

The first line contains integers nn and qq (4≤n≤2⋅1054 \le n \le 2 \cdot 10^5, 1≤q≤2⋅1051 \le q \le 2 \cdot 10^5), the number of vertices and the number of events.

Each of the next n−3n-3 lines contains integers xix_i and yiy_i (1≤xi,yi≤n1 \le x_i, y_i \le n), the labels of the vertices touched by the ii-th stick.

Each of the next qq lines starts with an integer tit_i (1≤ti≤21 \le t_i \le 2), the event type. If ti=1t_i = 1, four integers ai,bi,ci,dia_i, b_i, c_i, d_i (1≤ai,bi,ci,di≤n1 \le a_i, b_i, c_i, d_i \le n) follow, and the operation ((ai,bi),(ci,di))((a_i, b_i),(c_i, d_i)) is performed at that moment. The operation is guaranteed to be valid. If ti=2t_i = 2, one integer xix_i (1≤xi≤n1 \le x_i \le n) follows, and you must report the data for the fan triangulation at vertex xix_i for the current triangulation.

Output

For every event of type 2, in input order, print two integers on one line: the minimal number of operations, and the number of ways to reach the target triangulation with that many operations, modulo 109+710^9 + 7.

Examples3

  1. Example 1

    Input
    4 3
    1 3
    2 1
    1 1 3 2 4
    2 1
    
    Expected output
    0 1
    1 1
    
  2. Example 2

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

    Input
    9 3
    1 5
    1 7
    2 4
    2 5
    5 7
    7 9
    2 1
    1 2 5 1 4
    2 1
    
    Expected output
    4 12
    3 6