## You Can’t Write Science Fiction Better Than This

View as PDF

Points: 7
Time limit: 2.0s
Memory limit: 64M

Authors:
Problem type

Yesterday, Henning fell asleep while his chem teacher elaborated on the world of quantum mechanics. Unfortunately, the world of quantum mechanics is closer than he thinks.

The next day, Henning walks into Massey to realize that the school has rearranged itself into a collection of N locations numbered each floating in its own alternate dimension. There are two-way portals, each one taking exactly second to traverse and connecting two distinct locations. No two portals connect the same pair of locations. Since Henning is also a UHC grandmaster, he spends exactly 0 seconds outside of traversing portals.

Henning’s head might be a little frazzled by the destruction of physics, but he is not about to call in sick that day, since he has a math test. He needs to walk to his locker at location then go to his math class at location . The front entrance of the school, where Henning starts at, is at location . Due to the might of quantum mechanics, the locker, the classroom, and the entrance are not necessarily in distinct locations. The bell is about to ring, so what is the smallest amount of time it takes for Henning to get there?

#### Input Specifications

On the first line, , , , , in that order, each separated by a single space. On the next lines, there will be two distinct space separated integers and , signifying a portal that connects the locations and .

#### Output Specifications

The smallest amount of time in seconds it takes for Henning to walk from the front entrance to his math class while also passing through his locker. If there is no such path, output -1.

#### Sample Input 1

5 5 2 4
1 2
2 3
2 5
3 4
5 4

#### Sample Output 1

3

#### Explanation for Sample 1

Here is a visual representation, where each numbered circle represents a corresponding location and each line represents a portal. Henning can either walk the path or for a total of portal jumps, or seconds of time spent at the minimum.

#### Sample Input 2

6 4 3 2
1 2
3 4
6 5
4 5

#### Sample Output 2

-1

#### Sample Input 3

5 5 1 1
1 2
2 3
3 4
2 5
3 5

#### Sample Output 3

0
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.2698739469051361, "perplexity": 1449.201868476738}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 5, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2019-04/segments/1547583656530.8/warc/CC-MAIN-20190115225438-20190116011438-00210.warc.gz"}