#P6966. [NEERC2016] Cactus Construction
[NEERC2016] Cactus Construction
题目描述
Let us consider the following way of constructing graphs. Pick the number of colors . Let be the number of vertices in a graph. To build a graph, we use a workspace with several graphs in it. Each vertex of each graph has a color. Colors are denoted by integers from to . Initially, we have graphs in a workspace with one vertex in each graph, all colored with color , and no edges. The only vertex of i-th graph has number .
The following operations are permitted:
join a : join graphs containing vertices a and into one graph. No edges are added. Vertices a and must be in different graphs.
recolor a in graph containing vertex a recolor all vertices of color with color
connect a in graph containing vertex a create edges between all pairs of vertices where one vertex has color and the other has color If loops are not created. If such an edge already exists, then the second parallel edge is created. Multi-edges are not allowed in this problem, so this case must not occur.
At the end we should have a single graph and colors of its vertices do not matter.
The minimal number of colors , that can be used to construct a graph, is called a clique width of a graph. Clique width is one of the characteristics of graph complexity. Many NP-hard problems can be solved in polynomial time on graphs with bounded clique width, using dynamic programming on this process of building a graph. For a general graph, calculating the exact value of a clique width is known to be NP-hard. However, for some graph classes bounds on a clique width are known.
Cactus is a connected undirected graph in which every edge lies on at most one simple cycle. Intuitively cactus is a generalization of a tree where some cycles are allowed. Multi-edges (multiple edges between a pair of vertices) and loops (edges that connect a vertex to itself) are not allowed in a cactus. It is known that a clique width of a cactus does not exceed .
You are given a cactus. Find out how to build it in the described way using at most colors.
输入格式
The first line of the input file contains two integers and ; . Here is the number of vertices in the graph. Vertices are numbered from to . Edges of the graph are represented by a set of edge-distinct paths, where is the number of such paths.
Each of the following lines contains a path in the graph. A path starts with an integer followed by integers from to . These integers represent vertices of a path. Adjacent vertices in the path are distinct. The path can go to the same vertex multiple times, but every edge is traversed exactly once in the whole input file.
The graph in the input file is a cactus.
输出格式
In the first line print one integer -- the number of operations you need. This number should not be greater than . In the next lines print operations. Each operation is denoted by its first letter (j
for join, r
for recolor and c
for connect) and its arguments in the order they are described in the problem statement.
At the end, after applying all these operations, one should have one graph, which is equal to the cactus in the input. This means that there should be exactly one edge between each pair of vertices connected in the input graph, and no edges between vertices not connected in the input graph.
题目大意
有 个集合,初始第 个集合只包含第 个点,每个点的初始颜色都为 。要求使用下列 种操作构建出给定的仙人掌。输出方案,操作数不得多于 。
-
,将 所在的集合和 所在的集合合并成一个集合。
-
(),将 所在的集合中,所有颜色为 的点的颜色改为 。
-
,将 所在的集合中,每一个颜色为 的点连向每一个 颜色为 的点,不允许出现重边。
输入第一行为点数 和 条()边不重复的路径,每条边恰好会出现一次。接下来每行第一个数字 () 代表路径的点数,后面 个数字表示一条路径。
8 2
5 1 2 3 4 7
5 4 5 6 1 8
17
r 2 1 2
j 2 3
c 2 1 2
r 6 1 2
j 5 6
c 6 1 2
r 4 1 3
j 4 3
j 4 6
j 4 7
c 4 3 1
r 4 3 1
r 8 1 2
r 1 1 3
j 1 8
j 1 4
c 1 3 2
15 3
9 1 2 3 4 5 6 7 8 3
7 2 9 10 11 12 13 10
5 2 14 9 15 10
39
r 7 1 2
r 5 1 2
j 7 8
c 7 1 2
j 5 4
c 5 1 2
r 6 1 3
j 6 7
j 6 5
c 6 3 2
r 3 1 4
j 6 3
c 6 4 1
r 11 1 2
r 13 1 2
j 12 11
j 12 13
c 11 1 2
r 10 1 3
j 12 10
c 10 2 3
r 10 1 2
r 10 4 2
r 15 1 3
j 15 10
c 15 3 3
j 9 10
c 9 1 3
r 9 3 2
r 9 1 4
r 14 1 4
j 9 14
c 9 4 4
r 1 1 4
r 3 1 2
j 2 1
j 2 14
j 2 3
c 2 1 4
提示
Time limit: 2 s, Memory limit: 512 MB.