## MWC '15 #4 P4: Dealing with Knots

View as PDF

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

Authors:
Problem type

MathBunny123 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! MathBunny123 wants to check if string 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.

#### Input 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

• commented on Oct. 20, 2017, 10:57 a.m. edited

Shouldn't and not ? Or am I not understanding the problem correctly?

Also:

Each piece of string, aa, will only appear once as the first piece of string in a connection, a b.

Doesn't sample case 1 violate this? Two connections start from 3.

• commented on Oct. 20, 2017, 12:48 p.m.

The last line of input specifies the two pieces of string to be checked

• commented on April 17, 2016, 3:45 p.m. edit 4

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

• commented on April 17, 2016, 4:01 p.m.

Tangled