MFMOBILE - Mobile (Again)

no tags 

Fred is a baby. Above Fred's crib hangs a mobile. Fred is amused by this mobile. Fred has a twin sister, Mary. Above Mary's crib hangs another mobile. Fred wonders whether the mobile above his crib and the mobile above Mary's crib are the same. Help Fred.

A mobile is a collection of bars, strings, and decorative weights suspended from the ceiling. Each bar is suspended by a string tied to the exact centre of the bar. From each end of a bar hangs a string that is tied either to another bar or to a weight. The bars can rotate freely about their centres. Fred cannot tell two bars apart, even if they have different lengths. Fred also cannot tell two strings apart. Fred therefore considers two mobiles to be the same if the bars of one mobile can be rotated somehow to make the two mobiles appear identical.

Fred has even developed a notation for describing mobiles. He assigns each bar a distinct positive integer from 1 to the number of bars in the mobile, and he assigns the various objects negative integers. 1 always represents the bar suspended from the ceiling. (So, for example, a biplane might be represented by Fred as object -2, a crescent-moon might be object -57, and a star might be object -21.) Fred can only count down to -9999, so you can assume that he gave no objects lower numbers than -9999.

Input

The input contains two mobile descriptions. The first line of a mobile description contains a single nonnegative integer n (1 ≤ n ≤ 100000), indicating the number of bars in the mobile. On the next n lines, there are two numbers per line, with these two numbers representing the objects hanging from bar i.

Output

Output is composed of one line. Write "Fred and Mary have different mobiles." if Fred's information is enough to distinguish the two mobiles; otherwise, "Fred and Mary might have the same mobile.".

Example #1

Input:
5 
2 3 
4 5 
-1 -2 
-3 -4 
-5 -6 
5 
2 5 
-1 -2 
-3 -4 
-5 -6 
3 4

Output:
Fred and Mary might have the same mobile.

Example #2

Input:
5
2 3
4 5
-3 -4
-1 -2
-5 -6
5
2 5
-1 -2
-3 -4
-5 -6
3 4

Output:
Fred and Mary have different mobiles.

hide comments
abhijith reddy d: 2009-06-04 12:11:57

argh !! this shouldn't have been moved to the tutorial section ...:P

[Trichromatic] XilinX: 2009-05-20 03:11:22

I've moved this one to tutorial section because:
i) The mobile should be a tree.
ii) One can get Accepted assuming i) but actually the mobile is not always a tree.

abhijith reddy d: 2009-04-28 12:12:24

Got AC assuming the mobile to be a tree ;)
May be it just depends on how the user handles the insert procedure.

Last edit: 2009-04-28 12:33:04
Brian Bi: 2009-04-28 04:36:40

A bizarre but minimalist case:
3
2 2
3 3
-1 -2
3
3 3
-2 -1
2 2
-> Fred and Mary might have the same mobile.

abhijith reddy d: 2009-04-27 18:27:57

hmn...but according to the problem-statement/testdata the mobile should be a tree..
can u give an example ?

Last edit: 2009-04-27 18:47:18
JaceTheMindSculptor: 2009-04-26 19:21:35

OK guys. Sorry for the reaaaaally late reply. The mobile is not guaranteed to be a tree.

abhijith reddy d: 2009-04-26 01:23:30

Will this problem ever be back again ???

[Trichromatic] XilinX: 2009-04-15 02:54:18

Is a mobile a tree??I assume that and get Wrong Answer.

JaceTheMindSculptor: 2009-04-13 21:50:25

I was just calling him by whatever SPOJ showed me :P

Of course, I know about how good he is. Perhaps I should call him, Dr. Neal Wu.

Last edit: 2009-04-13 21:50:55
Brian Bi: 2009-04-13 21:32:46

Doesn't it seem a bit unfriendly to call a fellow high-school programmer by their full name? xD


Added by:JaceTheMindSculptor
Date:2009-04-12
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: C99 ERL JS-RHINO
Resource:Canadian Computing Competition 2008 Stage 2 Day 1 Problem C