Logo
(追記) (追記ここまで)

3547번 - Inspection 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB78151420.290%

문제

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 flight 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 n (2 ≤ n ≤ 100) — the number of points in the ski resort. The following n lines of the input file describe each point of the ski resort numbered from 1 to n. Each line starts with a single integer number mi (0 ≤ mi < n for i from 1 to n) and is followed by mi integer numbers aij separated by spaces. All aij are distinct for each i and each aij (1 ≤ aij ≤ n, aij ≠ i) represents a slope going downwards from point i to point aij . 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 k — the minimal number of helicopter flights that are needed to inspect all slopes. Then write k lines that describe inspection routes for each helicopter flight. Each route shall start with single integer number from 1 to n — 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 a line shall be separated by spaces. You can write routes in any order.

제한

예제 입력 1

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

예제 출력 1

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

힌트

출처

ICPC > Regionals > Northern Eurasia > Northern Eurasia Finals > NEERC 2009 I번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /