CF237D.T-decomposition

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You've got a undirected tree ss , consisting of nn nodes. Your task is to build an optimal T-decomposition for it. Let's define a T-decomposition as follows.

Let's denote the set of all nodes ss as vv . Let's consider an undirected tree tt , whose nodes are some non-empty subsets of vv , we'll call them xix_{i} . The tree tt is a T-decomposition of ss , if the following conditions holds:

  1. the union of all xix_{i} equals vv ;
  2. for any edge (a,b)(a,b) of tree ss exists the tree node tt , containing both aa and bb ;
  3. if the nodes of the tree tt xix_{i} and xjx_{j} contain the node aa of the tree ss , then all nodes of the tree tt , lying on the path from xix_{i} to xjx_{j} also contain node aa . So this condition is equivalent to the following: all nodes of the tree tt , that contain node aa of the tree ss , form a connected subtree of tree tt .

There are obviously many distinct trees tt , that are T-decompositions of the tree ss . For example, a T-decomposition is a tree that consists of a single node, equal to set vv .

Let's define the cardinality of node xix_{i} as the number of nodes in tree ss , containing in the node. Let's choose the node with the maximum cardinality in tt . Let's assume that its cardinality equals ww . Then the weight of T-decomposition tt is value ww . The optimal T-decomposition is the one with the minimum weight.

Your task is to find the optimal T-decomposition of the given tree ss that has the minimum number of nodes.

输入格式

The first line contains a single integer nn (2<=n<=105)(2<=n<=10^{5}) , that denotes the number of nodes in tree ss .

Each of the following n1n-1 lines contains two space-separated integers ai,bia_{i},b_{i} (1<=ai,bi<=n; aibi)(1<=a_{i},b_{i}<=n; a_{i}≠b_{i}) , denoting that the nodes of tree ss with indices aia_{i} and bib_{i} are connected by an edge.

Consider the nodes of tree ss indexed from 1 to nn . It is guaranteed that ss is a tree.

输出格式

In the first line print a single integer mm that denotes the number of nodes in the required T-decomposition.

Then print mm lines, containing descriptions of the T-decomposition nodes. In the ii -th (1<=i<=m)(1<=i<=m) of them print the description of node xix_{i} of the T-decomposition. The description of each node xix_{i} should start from an integer kik_{i} , that represents the number of nodes of the initial tree ss , that are contained in the node xix_{i} . Then you should print kik_{i} distinct space-separated integers — the numbers of nodes from ss , contained in xix_{i} , in arbitrary order.

Then print m1m-1 lines, each consisting two integers pi,qip_{i},q_{i} (1<=pi,qi<=m; piqi)(1<=p_{i},q_{i}<=m; p_{i}≠q_{i}) . The pair of integers pi,qip_{i},q_{i} means there is an edge between nodes xpix_{pi} and xqix_{qi} of T-decomposition.

The printed T-decomposition should be the optimal T-decomposition for the given tree ss and have the minimum possible number of nodes among all optimal T-decompositions. If there are multiple optimal T-decompositions with the minimum number of nodes, print any of them.

输入输出样例

  • 输入#1

    2
    1 2
    

    输出#1

    1
    2 1 2
    
  • 输入#2

    3
    1 2
    2 3
    

    输出#2

    2
    2 1 2
    2 2 3
    1 2
    
  • 输入#3

    4
    2 1
    3 1
    4 1
    

    输出#3

    3
    2 2 1
    2 3 1
    2 4 1
    1 2
    2 3
    
首页