#P3240. [HNOI2015] 实验比较

    ID: 2289 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划,dp数学2015并查集各省省选湖南

[HNOI2015] 实验比较

Description

Little D was invited to a lab to participate in a subjective experiment related to image quality assessment.

The dataset contains NN images, numbered 11 to NN. The experiment is conducted in several rounds. In each round, Little D is asked to look at two randomly selected images, and then, based on his subjective judgment, decide which image is better, or that their qualities are about the same.

We use the symbols “<<”, “>>”, and “==” to denote comparisons between images xx and yy (xx, yy are image indices): if within the context xx and yy are image indices, then x<yx < y means “the quality of image xx is better than that of yy,” x>yx > y means “the quality of image xx is worse than that of yy,” and x=yx = y means “images xx and yy have equal quality.” That is, in such contexts, “<<”, “>>”, and “==” respectively mean better quality, worse quality, and equal quality; in other contexts, these three symbols retain their usual meanings of less than, greater than, and equal to.

Reasoning rules for image quality comparisons (in the context where xx and yy are image indices):

  1. x<yx < y is equivalent to y>xy > x.
  2. If x<yx < y and y=zy = z, then x<zx < z.
  3. If x<yx < y and x=zx = z, then z<yz < y.
  4. x=yx = y is equivalent to y=xy = x.
  5. If x=yx = y and y=zy = z, then x=zx = z.

In the experiment, Little D needs to provide a subjective judgment for some image pairs (x,y)(x, y): either x<yx < y, or x=yx = y, or x>yx > y. After the experiment, Little D became interested in some global properties of this locally compared experiment.

Given the subjective experiment data, we define a legal quality sequence of these NN images as a string of the form “x1R1x2R2x3R3xN1RN1xNx_1 R_1 x_2 R_2 x_3 R_3 \dots x_{N-1} R_{N-1} x_N,” which can also be regarded as the set {xiRixi+11iN1}\{ x_i R_i x_{i+1} \mid 1 \leq i \leq N - 1 \}, where xix_i are image indices, x1,x2,,xNx_1, x_2, \ldots, x_N are pairwise distinct (i.e., no duplicate indices), RiR_i is either << or ==, and “legal” means that this quality sequence does not conflict with any of the subjective judgments.

For example: the quality sequence 3<1=23 < 1 = 2 conflicts with the subjective judgments “3>13 > 1, 3=23 = 2” (because in the sequence 3<13 < 1 and 1=21 = 2, hence 3<23 < 2, which conflicts with 3=23 = 2 in the judgments; meanwhile 3<13 < 1 conflicts with 3>13 > 1), but it does not conflict with the judgments “2=12 = 1, 3<23 < 2.” Therefore, given the judgments “3>13 > 1, 3=23 = 2,” both 1<3=21 < 3 = 2 and 1<2=31 < 2 = 3 are legal quality sequences, while 3<1=23 < 1 = 2 and 1<2<31 < 2 < 3 are illegal quality sequences.

Since some time has passed since the experiment, Little D has forgotten part of the subjective data. For each image XiX_i, Little D remembers at most one other image KXiK_{X_i} whose quality is not better than XiX_i. Altogether there are MM remembered judgments (0MN0 \leq M \leq N). The ii-th judgment involves the pair (KXi,Xi)(K_{X_i}, X_i) and is either KXi<XiK_{X_i} < X_i or KXi=XiK_{X_i} = X_i, and all XiX_i are pairwise distinct. Little D decides to use precisely these MM remembered judgments as all his subjective data.

Now, based on these subjective data, we ask you to help Little D compute how many different legal quality sequences there are for the NN images. We stipulate: if “x=yx = y” appears in a sequence, then swapping the positions of xx and yy results in the same sequence. Therefore: 1<2=3=4<51 < 2 = 3 = 4 < 5 and 1<4=2=3<51 < 4 = 2 = 3 < 5 are the same sequence, 1<2=31 < 2 = 3 and 1<3=21 < 3 = 2 are the same sequence, whereas 1<2<31 < 2 < 3 and 1<2=31 < 2 = 3 are different sequences, and 1<2<31 < 2 < 3 and 2<1<32 < 1 < 3 are different sequences.

As the number of legal quality sequences can be large, you must output the answer modulo 109+710^9 + 7.

Input Format

The first line contains two positive integers N,MN, M, the total number of images and the number of judgments that Little D still remembers.

The following MM lines each contain one judgment, in the form “x<yx < y” or “x=yx = y”.

Output Format

Output a single line containing one positive integer, the number of legal quality sequences modulo 109+710^9 + 7.

5 4
1 < 2
1 < 3
2 < 4
1 = 5
5

Hint

There are 5 different legal sequences, as listed below:

  • 1=5<2<3<41 = 5 < 2 < 3 < 4
  • 1=5<2<4<31 = 5 < 2 < 4 < 3
  • 1=5<2<3=41 = 5 < 2 < 3 = 4
  • 1=5<3<2<41 = 5 < 3 < 2 < 4
  • 1=5<2=3<41 = 5 < 2 = 3 < 4

For 100%100\% of the testdata, N100N \leq 100.

Translated by ChatGPT 5