is tangled with string ; your job is to tell him if those two pieces of string are connected to each other by any means (if string is connected to other pieces of string and one or many of those are connected to , then is still tangled with string ). His string is in such a mess that he managed to make the connections one way; they do not reciprocate.
needs string for his physics ISP. However, the string he has is a huge mess, it's stuck together and a lot of it is tangled (there are many different pieces). Luckily he has the legendary TangledStringAnalyzer9000. This revolutionary machine can scan the mess, assign each piece of string a number, and tell him which pairs of string are connected! wants to check if stringInput Specification
The first line of input will contain the number of analyzed connections or number of pieces of string, .
The next lines of input will contain the connection in the form, a b
, where is the first string, is the second string. .
The last line of input will be in the form, X Y
, the pair of string pieces which will be checked to see if they are tangled or not. Each piece of string, , will only appear once as the first piece of string in a connection, a b
.
Output Specification
Output Tangled
if string is connected to string , otherwise output Not Tangled
.
Sample Input
3
1 2
2 3
3 1
3 2
Sample Output
Tangled
Comments
Shouldn't and not ? Or am I not understanding the problem correctly?
Also:
Doesn't sample case 1 violate this? Two connections start from 3.
The last line of input specifies the two pieces of string to be checked
5 1 2 2 3 3 4 4 5 5 3 1 5
Tangled