#P8149. Emotional Entanglement

    ID: 21331 Type: Default 1000ms 256MiB

Emotional Entanglement

Emotional Entanglement

There are \(n\) positive real variables \(v_1,v_2,\dots,v_n\). You are given a series of operations that represent conditions on these variables or queries on their relations.

Operations come in the following types:

  • Type 1 Condition: Format: 1 a b c d. This indicates that it is known that there exist infinitely many functions \(f:\mathbb{R}\to\mathbb{R}\) satisfying \[ \frac{f(v_a)}{f(v_b)}=\frac{v_c}{v_d}, \] where indices are 1-indexed. Note that if \(v_a=v_b\) then this equation forces \(v_c=v_d\) (since \(1=\frac{v_c}{v_d}\)).
  • Type 2 Condition: Format: 2 a b. This indicates that it is known that there exist finitely many functions \(f:\mathbb{R}\to\mathbb{R}\) with \(f(v_a)\ne f(v_b)\). This fact forces \(v_a=v_b\) to hold.
  • Query 1: Format: 3 a b. Ask whether \(v_a=v_b\) always holds given the current constraints. Output Yes if they are forced to be equal, and No otherwise.
  • Query 2: Format: 4 a. Ask for the number of indices \(b\) (with \(1\le b\le n\)) such that \(v_a=v_b\) always holds. In other words, output the size of the equivalence class containing \(v_a\).

Note that the conditions propagate: for a Type 1 condition, if it is known that \(v_a=v_b\) then it forces \(v_c=v_d\). Such implications may cascade as further conditions or unions are added.

inputFormat

The first line contains two integers \(n\) and \(m\): the number of variables and the number of operations.

Each of the next \(m\) lines describes an operation in one of the following formats:

  • 1 a b c d — a Type 1 Condition
  • 2 a b — a Type 2 Condition
  • 3 a b — Query 1: check if \(v_a=v_b\)
  • 4 a — Query 2: count the number of variables equal to \(v_a\)

All indices are 1-indexed.

outputFormat

For each query operation (types 3 and 4), output a result on a separate line. For Query 1, output Yes if \(v_a\) and \(v_b\) are forced to be equal, or No otherwise. For Query 2, output an integer representing the size of the equivalence class of \(v_a\).

sample

5 7
2 1 2
1 1 2 3 4
3 1 2
3 3 4
3 1 3
2 3 5
4 3
Yes

Yes No 3

</p>