#P10935. 银河
银河
Problem Description
There are countless stars in the galaxy, but we only care about the brightest ones.
We use a positive integer to represent a star's brightness. The larger the value is, the brighter the star is. The minimum brightness is .
Now, among the stars we care about, pairs of relative brightness relationships have been determined.
Your task is to find the minimum possible value of the sum of brightness values of these stars.
Input Format
The first line contains two integers and .
Then follow lines. Each line contains three integers , describing the brightness relationship between a pair of stars . Star indices start from .
If , it means the brightness of and are equal.
If , it means the brightness of is less than the brightness of .
If , it means the brightness of is not less than the brightness of .
If , it means the brightness of is greater than the brightness of .
If , it means the brightness of is not greater than the brightness of .
Output Format
Output an integer representing the result.
If there is no solution, 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
Constraints: ,.
Translated by ChatGPT 5