#CODEFESTIVAL2016FINALC. Interpretation

Interpretation

Score : 400400 points

Problem Statement

On a planet far, far away, MM languages are spoken. They are conveniently numbered 11 through MM.

For CODE FESTIVAL 20XX held on this planet, NN participants gathered from all over the planet.

The ii-th (1iN)(1 \leq i \leq N) participant can speak KiK_i languages numbered Li,1,Li,2,...,Li,KiL_{i,1}, L_{i,2}, ..., L_{i,{}K_i}.

Two participants AA and BB can communicate with each other if and only if one of the following conditions is satisfied:

  • There exists a language that both AA and BB can speak.
  • There exists a participant XX that both AA and BB can communicate with.

Determine whether all NN participants can communicate with all other participants.

Constraints

  • 2N1052 \leq N \leq 10^5
  • 1M1051 \leq M \leq 10^5
  • 1KiM1 \leq K_i \leq M
  • ((The sum of all Ki)105K_i) \leq 10^5
  • 1Li,jM1 \leq L_{i,j} \leq M
  • Li,1,Li,2,...,Li,KiL_{i,1}, L_{i,2}, ..., L_{i,{}K_i} are pairwise distinct.

Partial Score

  • 200200 points will be awarded for passing the test set satisfying the following: N1000N \leq 1000, M1000M \leq 1000 and ((The sum of all Ki)1000K_i) \leq 1000.
  • Additional 200200 points will be awarded for passing the test set without additional constraints.

Input

The input is given from Standard Input in the following format:

NN MM

K1K_1 L1,1L_{1,1} L1,2L_{1,2} ...... L1,K1L_{1,{}K_1}

K2K_2 L2,1L_{2,1} L2,2L_{2,2} ...... L2,K2L_{2,{}K_2}

::

KNK_N LN,1L_{N,1} LN,2L_{N,2} ...... LN,KNL_{N,{}K_N}

Output

If all NN participants can communicate with all other participants, print YES. Otherwise, print NO.

4 6
3 1 2 3
2 4 2
2 4 6
1 6
YES

Any two participants can communicate with each other, as follows:

  • Participants 11 and 22: both can speak language 22.
  • Participants 22 and 33: both can speak language 44.
  • Participants 11 and 33: both can communicate with participant 22.
  • Participants 33 and 44: both can speak language 66.
  • Participants 22 and 44: both can communicate with participant 33.
  • Participants 11 and 44: both can communicate with participant 22.

Note that there can be languages spoken by no participant.

4 4
2 1 2
2 1 2
1 3
2 4 3
NO

For example, participants 11 and 33 cannot communicate with each other.