CF237D.T-decomposition
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You've got a undirected tree s , consisting of n 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 s as v . Let's consider an undirected tree t , whose nodes are some non-empty subsets of v , we'll call them xi . The tree t is a T-decomposition of s , if the following conditions holds:
- the union of all xi equals v ;
- for any edge (a,b) of tree s exists the tree node t , containing both a and b ;
- if the nodes of the tree t xi and xj contain the node a of the tree s , then all nodes of the tree t , lying on the path from xi to xj also contain node a . So this condition is equivalent to the following: all nodes of the tree t , that contain node a of the tree s , form a connected subtree of tree t .
There are obviously many distinct trees t , that are T-decompositions of the tree s . For example, a T-decomposition is a tree that consists of a single node, equal to set v .
Let's define the cardinality of node xi as the number of nodes in tree s , containing in the node. Let's choose the node with the maximum cardinality in t . Let's assume that its cardinality equals w . Then the weight of T-decomposition t is value w . The optimal T-decomposition is the one with the minimum weight.
Your task is to find the optimal T-decomposition of the given tree s that has the minimum number of nodes.
输入格式
The first line contains a single integer n (2<=n<=105) , that denotes the number of nodes in tree s .
Each of the following n−1 lines contains two space-separated integers ai,bi (1<=ai,bi<=n; ai=bi) , denoting that the nodes of tree s with indices ai and bi are connected by an edge.
Consider the nodes of tree s indexed from 1 to n . It is guaranteed that s is a tree.
输出格式
In the first line print a single integer m that denotes the number of nodes in the required T-decomposition.
Then print m lines, containing descriptions of the T-decomposition nodes. In the i -th (1<=i<=m) of them print the description of node xi of the T-decomposition. The description of each node xi should start from an integer ki , that represents the number of nodes of the initial tree s , that are contained in the node xi . Then you should print ki distinct space-separated integers — the numbers of nodes from s , contained in xi , in arbitrary order.
Then print m−1 lines, each consisting two integers pi,qi (1<=pi,qi<=m; pi=qi) . The pair of integers pi,qi means there is an edge between nodes xpi and xqi of T-decomposition.
The printed T-decomposition should be the optimal T-decomposition for the given tree s 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