CCC '00 S3 - Surfing

View as PDF

Submit solution

Points: 7
Time limit: 1.0s
Memory limit: 16M

Problem types
Canadian Computing Competition: 2000 Stage 1, Junior #5, Senior #3

Every Web Page is identified by a string of characters known as a URL (Uniform Resource Locator). Web Pages are formatted using HTML (Hypertext Markup Language). HTML has many codes, collectively known as markup, that allow the author to specify the format of the pages as well as to specify links to other pages. For this problem, we are concerned only with the markup that identifies links to other pages within a given page.

A link within the page is denoted <A HREF="URL"> where URL is the URL of some other page. A user viewing a page containing a link may click on the link to view the other page.

You are to write a program that reads a number of web pages and their associated URLs. For each link in each page, you must print the URL of the page containing the link, and the URL of the page referred to by the link. Following the last page, you are then given several pairs of URLs. For each pair you are to assume that you are viewing the page identified by the first URL, and determine whether it is possible to click a sequence of links so as to view the page identified by the second URL. If so, you should print Can surf from here to there. where here and there are the two URLs. If not you should print Can't surf from here to there.

Input Specification

The first line of input contains an integer n \le 100, the number of Web Pages. For each Web Page, there will be a line containing its URL, followed by several lines containing the page. The URL will consist of up to 80 non-blank printable characters and will not contain any quotation marks. The first line of the page will be <HTML> and the last line will be </HTML>. Each page will contain up to 100 links in the format described above. Each link will be contained within a single line of input. URLs in the link will be those of pages given in the input. The markup keywords A, HREF, and HTML will appear only in upper case.

Following the n pages will be several pairs of lines giving URLs required by the problem as specified above. The last line of input will be The End.

Output Specification

For each pair, print the appropriate message given above.

Sample Input

<HTML> <TITLE>This is the CCC page</TITLE>
Hello there boys
and girls.  <B>Let's</B> try <A HREF="http://abc.def/ghi"> a
problem </A>
<HTML> Now is the <TITLE>time</TITLE> for all good people to program.
<A HREF="">hello</A><A HREF="http://xxx">bye</A>
<TITLE>Weird and Wonderful World</TITLE>
The End

Sample Output

Link from to http://abc.def/ghi
Link from http://abc.def/ghi to
Link from http://abc.def/ghi to http://xxx
Can surf from to
Can't surf from to


  • 2
    Genius3435  commented on May 29, 2021, 4:35 p.m.

    To clarify what the problem wants, the link from __a__ to __b__ stuff should be exactly like that, without a period.

    Then for the queries about the paths, it should be something like Can['t] surf from __a__ to __b__., with a period.

    And if you can't find the error in your program, here is the link to the test cases.

  • 2
    Julien  commented on Feb. 1, 2021, 6:28 p.m.

    I keep on getting WA on the 2nd attempt. Does anyone know why?

  • 3
    GreenRobot  commented on June 11, 2020, 11:11 a.m.

    What a great problem! This is how the page rank algorithm for google works. By measuring the amount of backlinks to any given website.

  • 3
    Evang  commented on April 17, 2020, 9:58 p.m. edited

    Can </HTML> be on the same line as the web page?

  • 0
    MinzeLI  commented on March 19, 2020, 2:50 p.m. edited

    can someone please check my code, I don't know what is wrong

  • 0
    huisfle  commented on Jan. 11, 2020, 10:49 a.m. edit 2

    Is it possible for a page to have multiple links? Nvm I read the question again.

  • 15
    Dan13llljws  commented on Dec. 26, 2019, 1:21 p.m. edited

    It is really sad when you forgot to print the period at the end and you have absolutely no idea y your code is wrong

  • -21
    EdwinSun  commented on Oct. 27, 2019, 3:52 p.m. edit 2

    This comment is hidden due to too much negative feedback. Click here to view it.

  • 0
    Falseman1024  commented on Jan. 14, 2019, 10:42 a.m. edit 3

    Is there any specific output format that it judges on? My clipped output matches the one shown on the sample, but it gives WA. Any insights?

    NVM: It's all good. Check your work carefully.

  • -31
    echometer  commented on Sept. 24, 2018, 10:43 a.m. edited

    This comment is hidden due to too much negative feedback. Click here to view it.

  • 2
    lKunelk  commented on Nov. 30, 2016, 9:09 p.m.

    In order to get my solution in Java to AC I had to trim the first input from white-space. Seems like unintentional input.

    • 1
      Kirito  commented on Nov. 30, 2016, 10:03 p.m.

      Should be fixed. Thank you for pointing that out.

  • 0
    minecraftyugi  commented on Sept. 14, 2016, 9:53 p.m.

    In the question description, it says to print in the format "Can surf from here to there." and "Can't surf from here to there.". The actual answer doesn't have a period at thee end of the sentence. Also, the fourth line of the sample output has a period when it shouldn't.

    • 0
      Kirito  commented on Sept. 15, 2016, 9:02 a.m. edit 4

      The Official PDF has that part cut off.

      Edit: Question now has all output terminate in periods.