<PREV Problem:
NEXT>
Solved by 151 users: ...
 < 
 < 
 < 
 < 
 < 
 < 
 < 
 < 
 < 
 < 

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 190ms

SW soft NIX
ID = 23.20.13.165