I want to create an program that finds the checks make your own adventure books;

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

  1. ensure that every page can be reached – otherwise, there is no reason to pay to print a page which no one can ever read
  2. 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.

Input SpecificationThe first line of input contains N (1 ≤ N ≤ 10000), the number of pages in the book. Each ofthenextN linescontainanintegerMi (1 ≤ i ≤ N;0 ≤ Mi ≤ N),whichisthenumber of different options from page i, followed by Mi 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 M1 +M2 +···+MN isatmost10000.If Mi=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.For4oftheavailable15marks,N ≤100,Mi ≤10for1≤i≤N.For an additional 3 of the available 15 marks, the book is guaranteed to have no cycles. Foranadditional4oftheavailable15marks,N ≤1000,Mi ≤25for1≤i≤N.

Output SpecificationThe 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.

Sample Input3 2 2 3 0 0

Sample OutputY 2

This is my code so far:

public static void main(String[] args) {Scanner input=new Scanner(System.in);int numberOfPages=input.nextInt();LinkedList book=new LinkedList();for (int i=0; i < numberOfPages; i++) {int choices=input.nextInt();int[] page=new int[choices];if (choices > 0) for (int j=0; j < choices; j++) {page[j]=input.nextInt();}book.add(page);}//Debuggingfor (int i=0; i < book.size(); i++) {System.out.println(book.get(i));}}
share|improve this question
  • Homework problem?– alephtwoFeb 14 at 20:12
  • What is your question?– homeFeb 15 at 7:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.