VM7WC '16 #3 Silver - Can Shahir even get there?!

View as PDF

Points: 5
Time limit: 1.0s
Memory limit: 64M

Author:
Problem type

Shahir was already taped shut in the box when it occurred to him that he didn't know if it was possible to get from his house to his prom date's. That's no problem: he asks one of the friends that will deliver him, Dhruvit, to check.

There are houses in Shahir's neighbourhood and roads that connect those houses. Each road connects two houses. All roads can be traveled down both directions. Each house is distinctly numbered and identified by a number in the range .

Shahir lives in house . His date lives in house . Is there a path of roads to follow such that Dhruvit can drive the packaged Shahir from house to house ? Dhruvit wrote (and you, vicariously, will write) a program to answer that question.

Input Specification

The first line will contain four integers, separated by spaces:

• : The number of houses in Shahir's neighbourhood.
• : The number of roads in Shahir's neighbourhood.
• : Shahir lives in house .
• : Shahir's date lives in house .

The next lines contain two space-separated integers and , denoting a road that connects house with house . Two roads will never connect the same two houses.

Output Specification

On a single line, print GO SHAHIR! if Shahir can make it to his date's house. Otherwise, print NO SHAHIR!.

Sample Input 1

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

Sample Output 1

GO SHAHIR!

Explanation for Sample 1

Here is the graph of Shahir's neighbourhood:

Shahir's house is house . His date's house is at house . Dhruvit can drive Jeffrey from houses to by following the path or .

Sample Input 2

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

Sample Output 2

NO SHAHIR!

Explanation for Sample 2

This map of Shahir's neighbourhood is the same as the one in Sample 1, but the edge between houses and is removed. As a result, Dhruvit can no longer drive Shahir to his date's house.

• commented on Jan. 25, 2024, 1:17 a.m.

Im just Gonna put Duct tape on Shahir's Box.

• commented on Nov. 24, 2021, 7:30 p.m.

This is a great problem for an introduction to graph theory

• commented on Oct. 4, 2017, 2:12 p.m.

Note that even though the first sample case has , the actual test data has .

• commented on Jan. 24, 2016, 12:19 a.m. edited

I keep getting WA on #5. I'm probably in the wrong here, but I'm just checking as I'm the only Python 2 submission, and I have gotten the short end of the data precision stick before...

EDIT: Nevermind, corner cases are my life! Thanks all!

• commented on Feb. 11, 2016, 2:49 p.m.

yes there is a problem, you have to check all of the corner cases.