<PREV Problem:
NEXT>
Solved by 151 users: ...
UserDateAttemptTimeCMSC
lysy14 may 2010Python2501.50244 
svirg08 aug 2007Python400.17246 
Philip_PV04 aug 2008C++1200.01311 
Philip_PV04 aug 2008C++1000.01316 
Philip_PV04 aug 2008C++1100.01316 
fetetriste20 apr 2008C++500.02316 
tomek19 feb 2006C++600.02322 
gbalag07 sep 2005C++100.02328 
Philip_PV04 aug 2008C++800.01335 
Igor_Kvasov01 dec 2014C++700.01336 
wojtekt15 mar 2006C++100.02339 
lcosvse03 dec 2006C++400.03343 
zmy28 oct 2006C++300.04343 
Languages
C++
102
Kylix
16
FPC
16
C
9
Java
8
Python
2
Ruby
1
 > 
 > 
 > 
 > 
 > 
 > 
 > 
 > 
 > 
 > 

Love cycle

Time limit = 5 seconds

Love-cycle is a company in witch each loves exactly one person from this company and "love-arrows" form a cycle. Size of company should be greater than 2.

Your program should find maximum size love-cycle.

Input Th first line contains number of "loves" M, 1 ≤ M ≤ 500, then M lines with "love-arrows" description follow. Different persons have different names. A person's name is word consisting of latin letters A..Za..z. Length of a name is less then 20. One person may love many persons.

Output Size of maximum love-cycle or 0 if it does not exists.

Input#1
6
Kolya Olya
John Jessy
Jessy Kolya
Misha Olya
Olya John
Misha Jessy
Output#1
4

Input#2
2
Kolya Olya
Olya Kolya
Output#2
0

Author:
Voroztsov Artem

<PREV | Problem set | Search related messages | NEXT>


© acm.mipt DevGroup
The page was generated in 170ms

SW soft NIX
ID = 3.95.139.100