Under construction

Still being built. Things may change

Ghost

Time limit1sMemory limit1024 MB

Summary
Given a tree plus a ring road through its leaves, build a tree decomposition with at most 4N bags of size 4 or less, each vertex's bags connected.
Level

Hard9 of 10

Topics
Graph, Tree, Implementation
Solved
No attempts yet

Problem

A ghost is haunting South Korea. The ghost of KOI 2022 Round 2...

The KOI city has NN intersections and N−1N - 1 bidirectional roads, and any two distinct intersections can reach each other using only roads. In other words, the road network is a tree. The roads lie on a two-dimensional plane, and no two roads cross except at their endpoints.

Until a few decades ago, KOI city was a small town. As people moved in, it grew quickly. During this rapid expansion, the mayor numbered the intersections from 11 to NN for administrative convenience. The numbering has the following properties.

  • Intersection 11 is the city center, and it is adjacent to at least 22 roads.
  • The numbers form one of the preorder traversals of the tree rooted at intersection 11.
  • For every intersection, look at the adjacent intersections (directly connected by a road) and pick the one with the smallest number. Starting from that intersection, list the numbers of the adjacent intersections in counterclockwise order. The numbers increase.

As more people arrived, traffic congestion got worse. To deal with it, the mayor connected the intersections with the weakest transport links, meaning those adjacent to exactly one road, with an outer ring road. Let {v1,v2,…,vk}\{v_1, v_2, \dots, v_k\} be the numbers of the intersections adjacent to exactly one road, sorted in increasing order. For every 1≤i≤k1 \le i \le k, the mayor built a bidirectional road between intersection viv_i and intersection v(i mod k)+1v_{(i \bmod k)+1}. Because of the numbering, the ring roads can be added so that no two roads cross except at their endpoints.

Workers do not want to turn a tree into a graph. Congestion relief shortens commutes, and capitalists then find it easier to exploit workers. Workers want to return to the good old days when HLD and centroid decomposition could be done on the KOI city tree. First, they plan to overthrow the capitalists in a socialist revolution. Then they want to build a new tree as follows, to rebuild the structure of the original KOI city.

  • The new tree has at most 4N4N vertices. If the new tree has KK vertices, number them 1,2,…,K1, 2, \ldots, K.
  • Vertex ii of the new tree has a set XiX_i, which is a subset of {1,…,N}\{1, \ldots, N\}.
  • For every road (u,v)(u, v) of the original KOI city, there is some set XiX_i that contains both uu and vv. Roads here include the original tree roads and the outer ring roads.
  • For every 1≤j≤N1 \le j \le N, let SjS_j be the set of new tree vertices ii with j∈Xij \in X_i. Each SjS_j must be nonempty and revolutionary.
  • For every ii, ∣Xi∣≤4|X_i| \le 4 must hold. (Solutions with ∣Xi∣≤5|X_i| \le 5 may receive partial credit.)

A vertex subset SS of the new tree is revolutionary if the following holds. For any two distinct vertices uu and vv in SS, if uu and vv can be connected by walking through the new tree using only vertices of SS, then we say uu and vv are "connected within SS". SS is revolutionary when every pair of distinct vertices u,vu, v in SS is always connected within SS.

For example, consider the following new tree.

If S={1,2,3,4,5,6}S = \{1, 2, 3, 4, 5, 6\}, then (1,2)(1, 2), (3,5)(3, 5), and (4,6)(4, 6) are each connected within SS. However, (1,6)(1, 6) and (2,6)(2, 6) are not connected within SS.

Given the road network of KOI city, output the new tree and the set XiX_i of each vertex.

Input

The first line contains NN, the number of intersections in KOI city.

The next N−1N - 1 lines follow. The ii-th of these lines contains one integer pip_i, which means there is a bidirectional road between intersection pip_i and intersection i+1i + 1.

The roads given in the input are not the outer ring roads.

Output

On the first line, print KK, the number of vertices in the new tree. It must satisfy 1≤K≤4N1 \le K \le 4N.

Next, print KK lines. The first integer on the ii-th line is the size of XiX_i, followed by the ∣Xi∣|X_i| distinct integers of XiX_i, separated by spaces.

Then print K−1K - 1 lines describing the edges of the new tree, in order.

A valid answer always exists.

Constraints

  • 4≤N≤100 0004 \le N \le 100\,000
  • 1≤pi≤i1 \le p_i \le i

Hint

XiX_i may be the empty set.

If there were no size limit on XiX_i, a trivial answer would exist: K=1K = 1 and X1={1,2,…,N}X_1 = \{1, 2, \ldots, N\}.

Examples1

  1. Example 1

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