#P3275. [SCOI2011] 糖果
[SCOI2011] 糖果
Description
There are children in a kindergarten. Teacher wants to distribute candies to them, and every child must receive at least one candy. However, the children can be jealous and may raise some requests. For example, Xiao Ming does not want Xiao Hong to receive more candies than he does. Therefore, when distributing candies, needs to satisfy requests from the children. Since the total number of candies is limited, wants to know the minimum number of candies he needs to prepare so that every child receives candies and all requests are satisfied.
Input Format
The first line contains two integers . The next lines each contain integers , describing a request from the children.
- If , the -th child must receive the same number of candies as the -th child.
- If , the -th child must receive fewer candies than the -th child.
- If , the -th child must receive no fewer candies than the -th child.
- If , the -th child must receive more candies than the -th child.
- If , the -th child must receive no more candies than the -th child.
Output Format
Output a single integer: the minimum number of candies needs to prepare. If it is impossible to satisfy all the requests, output .
5 7
1 1 2
2 3 2
4 4 1
3 4 5
5 4 5
2 3 5
4 5 1
11
Hint
For of the testdata, .
For of the testdata, , , .
: Added sets of Hack testdata.
Translated by ChatGPT 5
京公网安备 11011102002149号