Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Question - : Consider a set of web pages, numbered from 1 to N . Each web page has links to one or more web
Question : Consider a set of web pages, numbered from to N Each web page has links to one or more web pages. Clicking on a link in a page, takes one to the other web page. You are provided numbers of two web pages viz, starting web page and end web page. Your task is to find the minimum number of clicks required to reach the end page from the start page. If end page cannot be reached from start page, print as the output. For better understanding refer Examples section.
Constraints
N
L
Input
First line contains an integer N denoting number of web pages.
Next N lines contain L space separated integers depicting linked webpage numbers from that webpage
Output
Print the minimum number of clicks required to open the end page from start page. If not possible, print as output.
Time Limit secs
Example
Input
Output
Explanation:
First line conveys that there is total pages.
Second line conveys that there are links from page to pages and
Third line conveys that there is a link from page to page
Fourth line conveys that there are links from page to pages and
Fifth line conveys that there are links from page to pages and
Sixth line conveys that there is a links from page to page itself.
Seventh line conveys that starting page is and ending page is
From page we can open only page From page we can open page From page we can open page So minimum clicks are required, and this is the output.
Example
Input
Output
Explanation:
First line conveys that there is total pages.
Second line conveys that there are links from page to page
Third line conveys that there is a link from page to page
Fourth line conveys that there are links from page to page
Since there is no way to reach from page to page print as output.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started