Problem H
British Menu

Since you are in Britain, you definitely want to try British food. Unfortunately you will only have a single free evening, so you decided to try all the food you can get in one run. You plan a gigantic meal where you eat one British dish after the other. Clearly not every order of dishes is appropriate. For example, it is not acceptable to eat Blood Pudding directly after Cornish Hevva Cake, but it would be perfectly fine if you chose to eat Baked Beans in between.
You have compiled a comprehensive list of British dishes. For each dish you have also decided which other dishes are fit to be eaten directly afterwards. A menu is a sequence of dishes such that each dish (except the first) is fit to be eaten directly after the previous dish.
After some time studying the list of dishes, you noticed
something odd: Whenever it is possible to find a menu in which
a dish occurs twice (for example dishes
But who wants to eat the same dish twice anyway? Clearly, you want to know how many dishes there can be in a menu without repeating any dish!
Input
The input consists of:
-
One line with two integers
( , ), the number of dishes and compatibilities. -
lines, each containing two integers and ( ), indicating that you can eat dish immediately after dish .
Dishes are numbered from
Output
A single integer indicating the maximum number of courses in a menu without repeated dishes.
Sample Input 1 | Sample Output 1 |
---|---|
4 3 1 2 2 3 2 4 |
3 |
Sample Input 2 | Sample Output 2 |
---|---|
7 7 1 2 2 3 3 4 4 5 5 2 4 6 5 7 |
6 |