#2625. [Neerc2009] Inspection

[Neerc2009] Inspection

题目描述

You are in charge of a team that inspects a new ski resort. A ski resort is situated on several mountains and consists of a number of slopes. Slopes are connected with each other, forking and joining. A map of the ski resort is represented as an acyclic directed graph. Nodes of the graph represent different points in ski resort and edges of the graph represent slopes between the points, with the direction of edges going downwards. Your team has to inspect each slope of the ski resort. Ski lifts on this resort are not open yet, but you have a helicopter. In one fiight the helicopter can drop one person into any point of the resort. From the drop off point the person can ski down the slopes, inspecting each slope as they ski. It is fine to inspect the same slope multiple times, but you have to minimize the usage of the helicopter. So, you have to figure out how to inspect all the slopes with the fewest number of helicopter flights.

给张有向无环图,问至少多少条路径能够覆盖所有的边(可以重复)。

输入格式

The first line of the input file contains a single integer number nn - the number of points in the ski resort. The following nn lines of the input file describe each point of the ski resort numbered from 11 to nn. Each line starts with a single integer number mim_i (0mi<n0 \leq m_i < n for ii from 11 to nn) and is followed by mi integer numbers ai,ja_{i,j} separated by spaces. All ai,ja_{i,j} are distinct for each ii and each ai,ja_{i,j} represents a slope going downwards from point ii to point ai,ja_{i,j}. Each point in the resort has at least one slope connected to it.

输出格式

On the first line of the output file write a single integer number kk - the minimal number of helicopter flights that are needed to inspect all slopes. Then write kk lines that describe inspection routes for each helicopter flight. Each route shall start with single integer number from 11 to nn - the number of the drop off point for the helicopter flight, followed by the numbers of points that will be visited during inspection in the corresponding order as the slopes are inspected going downwards. Numbers on aa line shall be separated by spaces. You can write routes in any order.

8
1 3
1 7
2 4 5
1 8
1 8
0
2 6 5
0
4

数据规模与约定

对于 100%100\% 的数据,2n1002 \leq n \leq 1001ai,jn1 \leq a_{i,j} \leq n

题目来源

Neerc2009