#graph306. SCOI2011, 糖果
SCOI2011, 糖果
Candy
Problem Source
SCOI 2011
Problem Description
There are children in the kindergarten. Teacher now wants to distribute candies to these children; every child must receive at least one candy. But the children are jealous and always make some demands. For example, Xiao Ming does not want Xiao Hong to get more candies than him. So while distributing candies, must satisfy demands from the children. The kindergarten's candies are always limited, and wants to know the minimum number of candies he must prepare so that every child gets at least one candy and all the children's demands are satisfied.
Input Format
The first line of the input contains two integers (). The next lines describe the relations that must be satisfied; each line contains three numbers ():
- If , the number of candies child gets must equal the number child gets.
- If , the number child gets must be strictly less than the number child gets.
- If , the number child gets must be no less than the number child gets.
- If , the number child gets must be strictly greater than the number child gets.
- If , the number child gets must be no greater than the number child gets.
Output Format
Output one line: the minimum number of candies teacher must prepare. If it is impossible to satisfy all the children's demands, output .
Sample Input
5 7
1 1 2
2 3 2
4 4 1
3 4 5
5 4 5
2 3 5
4 5 1
Sample Output
11