RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
R03544

J5. Choose your own path

Unrated 레이팅 미적용
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

There is a genre of fiction called choose your own
adventure
books.
These books allow the reader to make choices for
the characters which altersthe outcome of the story.

For example, after reading the first page of a book, the reader may
be asked a choice, such as “Do you pick up the rock?” If the reader
answers “yes”, they are directed to continue reading on page 47, and if
they choose “no”, they are directed to continue reading on page 18. On
each of those pages, they have further choices, and so on, throughout
the book. Some pages do not have any choices, and thus these are the
“ending” pages of that version of the story. There may be many such
ending pages in the book, some of which are good (e.g., the hero finds
treasure) and others which are not (e.g., the hero finds a leftover
sandwich from 2001).

You are the editor of one of these books, and you must examine two
features of the choose your own adventure book:

  • ensure that every page can be reached – otherwise, there is no
    reason to pay to print a page which no one can ever read;

  • find the shortest path, so that readers will know what the
    shortest amount of time they need to finish one version of the
    story.

Given a description of the book, examine these two features.

제약

\((1 \leq N \leq 10000)\)
\((1 \leq i \leq N; 0 \leq M_i \leq N)\)
\(N \leq 100\)
\(M_i \leq 10\)
\(1 \le i \le N\)
\(N \leq 1000\)
\(M_i \le 25\)

입력 형식

The first line of input contains \(N\)
\((1 \leq N \leq 10000)\), the number
of pages in the book. Each of the next \(N\) lines contain an integer \(M_i\) \((1 \leq i \leq N; 0 \leq M_i \leq N)\), which is the number of different
options from page \(i\), followed by
\(M_i\) space-separated integers in the
range from \(1\) to \(N\), corresponding to each of the pages to
go to next from page \(i\). It will
also be the case \(M_1 + M_2 + \cdots + M_N\) is at most 10000.

If \(M_i = 0\), then page \(i\) is an ending page (i.e., there are no
choices from that page). There will be at least one ending page in the
book.

Note that you always begin the book on page 1.

For 4 of the available 15 marks, \(N \leq 100\), \(M_i \leq 10\) for \(1 \le i \le N\).

For an additional 3 of the available 15 marks, the book is guaranteed
to have no cycles.

For an additional 4 of the available 15 marks, \(N \leq 1000\), \(M_i \le 25\) for \(1 \le i \le N\).

출력 형식

The output will be two lines. The first line will contain
Y if all pages are reachable, and
N otherwise. The last line will contain a
non-negative integer \(K\), which is
the shortest path a reader can take while reading this book. There will
always be a finite shortest path.

예제 1
입력
3
2 2 3
0
0
출력
Y
2
설명

Since we start on page 1, and can reach both page 2 and page 3, all
pages are reachable. The only paths in the book are \(1 \rightarrow 2\) and \(1 \rightarrow 3\), each of which is 2 pages
in length.

예제 2
입력
3
2 2 3
0
1 1
출력
Y
2
설명

Every page is reachable, since from page 1, we can reach pages 2 and 3.
The shortest path is the path 1 \(\rightarrow\) 2, which contains two
pages.

문제 정보

생성자가 기록되지 않았습니다.

출처 CCC 2018 Junior

평가 및 의견

J5. Choose your own path

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

J5. Choose your own path

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8