#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 11.

Now, among the NN stars we care about, MM 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 NN stars.

Input Format

The first line contains two integers NN and MM.

Then follow MM lines. Each line contains three integers T,A,BT, A, B, describing the brightness relationship between a pair of stars (A,B)(A, B). Star indices start from 11.

If T=1T = 1, it means the brightness of AA and BB are equal.
If T=2T = 2, it means the brightness of AA is less than the brightness of BB.
If T=3T = 3, it means the brightness of AA is not less than the brightness of BB.
If T=4T = 4, it means the brightness of AA is greater than the brightness of BB.
If T=5T = 5, it means the brightness of AA is not greater than the brightness of BB.

Output Format

Output an integer representing the result.

If there is no solution, output 1-1.

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: 1N1000001\le N \le 1000001M1000001\le M \le 100000.

Translated by ChatGPT 5