301268: CF237D. T-decomposition

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

T-decomposition

题意翻译

有一个编号从 $1n$ 的无向树 $s$,现在给出 $n-1$ 条边,将所有点的集合记为$V$,$V$ 的非空子集记为 $X_i$ 当满足下列三个条件时:所有的 Xi 的并集等于 $V$、树$s$ 的任意一条边 $(a,b)$ 都存在一个结点$t\,$包含 $a,b$、树 $t$ 的所有结点包含树 $s$ 的结点 $a$ 形成树的连通子树,称为一个 $T$-分解 现在将结点 $X_i$ 的权重定义为 $T$-分解中一个结点中原来树的结点中点编号最大的编号,构造一个最小权重的$T$ 分解 首先输出一个数$m$ 代表最佳$T$分解的结点个数,然后输出$m$ 个点的编号,再输出最佳$T$分解的$m-1$条边

题目描述

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 $ x_{i} $ ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF237D/c0bc8edf765059610981073a74f375f211ff2612.png). The tree $ t $ is a T-decomposition of $ s $ , if the following conditions holds: 1. the union of all $ x_{i} $ equals $ v $ ; 2. for any edge $ (a,b) $ of tree $ s $ exists the tree node $ t $ , containing both $ a $ and $ b $ ; 3. if the nodes of the tree $ t $ $ x_{i} $ and $ x_{j} $ contain the node $ a $ of the tree $ s $ , then all nodes of the tree $ t $ , lying on the path from $ x_{i} $ to $ x_{j} $ 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 $ x_{i} $ 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<=10^{5}) $ , that denotes the number of nodes in tree $ s $ . Each of the following $ n-1 $ lines contains two space-separated integers $ a_{i},b_{i} $ $ (1<=a_{i},b_{i}<=n; a_{i}≠b_{i}) $ , denoting that the nodes of tree $ s $ with indices $ a_{i} $ and $ b_{i} $ 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 $ x_{i} $ of the T-decomposition. The description of each node $ x_{i} $ should start from an integer $ k_{i} $ , that represents the number of nodes of the initial tree $ s $ , that are contained in the node $ x_{i} $ . Then you should print $ k_{i} $ distinct space-separated integers — the numbers of nodes from $ s $ , contained in $ x_{i} $ , in arbitrary order. Then print $ m-1 $ lines, each consisting two integers $ p_{i},q_{i} $ $ (1<=p_{i},q_{i}<=m; p_{i}≠q_{i}) $ . The pair of integers $ p_{i},q_{i} $ means there is an edge between nodes $ x_{pi} $ and $ x_{qi} $ 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

Input

题意翻译

### 题目描述 给定一棵 $n$ 个结点的无根树 $s$,它的点集为 $V$。你需要构造出一棵无根树 $t$,每个结点 $x_i$ 是 **$V$ 中的一个非空子集**。这棵树需要满足下列要求: - 所有 $x_i$ 的并集为 $V$。 - 对于树 $s$ 中的任意一条边 $(a,b)$,在 $t$ 中都能够找到一个集合 $x$ 使得 $a,b\in x$。 - 对于树 $s$ 中的任意一个点 $a$,所有在 $t$ 中包含了 $a$ 的集合构成了一个连通块。 设你构造出来的树 $t$ 的价值为 $t$ 中最大集合的大小。你的构造需要满足在价值最小的前提下,集合个数最少。$1\le n\le 10^5$。 ### 输入格式 第一行,输入 $n$。 接下来 $n-1$ 行,每行输入两个数 $a,b$ 表示树 $s$ 中的一条边。 ### 输出格式 第一行,输出 $t$ 中的集合个数 $k$。 接下来 $k$ 行,每行表示一个集合。第一个数输出集合的大小 $p$,接下来输出 $p$ 个数表示集合中的元素。 接下来 $k-1$ 行,每行输出两个数 $a,b$ 表示连接树 $t$ 中的第 $a$ 个和第 $b$ 个集合。

加入题单

算法标签: