
Fax McClad, Croneria's most meticulous bounty hunter, is going to prepare a dish for Thanksgiving! Fax prepared a turkey last year, so this year, he will cook something different.
There are
Fax wants to have one unit of item
Dankey Kang, Fax's enemy, wants to ruin Fax's Thanksgiving, so he will steal some food items from Fax so that he cannot have item
Constraints
Subtask | Points | Additional Constraints |
---|---|---|
1 | 10 | There is exactly |
2 | 25 | |
3 | 25 | |
4 | 40 | None |
Input Specification
The first line will contain integers
Each of the next
- The first integer is the target item.
- The second integer is the number of required items.
- The remaining integers are the required items.
The last line will contain
Sample Input 1
8 3
1 2 4 5
4 2 2 3
5 2 6 7
1 2 1 1 3 0 0 10
Sample Output 1
3
Explanation for Sample Output 1
Dankey Kang can steal item
It is not possible to ruin Fax's Thanksgiving by stealing 0 2 1 0 3 0 0 10
. Fax can follow the second recipe, and then the first recipe, to produce item
Sample Input 2
3 2
2 1 3
3 1 2
0 0 1
Sample Output 2
0
Comments
The problem is a little unclear. What is the meaning of "each item will appear at most once as a required item in a recipe"? Can an item appear in two recipes? Can there be a cycle, such as item 2 requires item 3 and item 3 also requires item 2?
Each item cannot appear in two recipes. Each item will only have at most one recipe, and can only belong to at most one recipe.
Can there be a cycle, such as item 2 requires item 3 and item 3 also requires item 2? A cycle seems satisfy all the conditions you mentioned. Thanks
If there were to be a cycle, it is evident that it wouldn't have any effect on the final solution, since neither of the cycled ingredients would actually be part of a recipe to create item one, due to the fact that each item can belong to at most one recipe.
Thanks a lot. Now I understand that no cycles are reachable from item 1.
Edit: In that case, I have no idea what I'm talking about lmao
No, it is possible to have cycles, but cycles do not impact the final solution. Please see aeternalis1 comment. Not sure if system test cases include cycles.