B - Everyone is Friends Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 200200

問題文

1,2,,N1,2,\ldots,N の番号がついた NN 人の人がいます。

MM 回の舞踏会が行われました。 ii (1iM)(1\leq i \leq M) 回目の舞踏会には kik_i 人が参加し、参加した人は人 xi,1,xi,2,,xi,kix_{i,1},x_{i,2},\ldots,x_{i,k_i} でした。

どの二人も少なくとも 11 回同じ舞踏会に参加したか判定してください。

制約

  • 2N1002\leq N \leq 100
  • 1M1001\leq M \leq 100
  • 2kiN2\leq k_i \leq N
  • 1xi,1<xi,2<<xi,kiN1\leq x_{i,1}<x_{i,2}<\ldots < x_{i,k_i}\leq N
  • 入力は全て整数

入力

入力は以下の形式で標準入力から与えられる。

NN MM
k1k_1 x1,1x_{1,1} x1,2x_{1,2} \ldots x1,k1x_{1,k_1}
\vdots
kMk_M xM,1x_{M,1} xM,2x_{M,2} \ldots xM,kMx_{M,k_M}

出力

どの二人も少なくとも 11 回同じ舞踏会に参加した場合 Yes を、そうでない場合 No を出力せよ。


入力例 1Copy

Copy
3 3
2 1 2
2 2 3
2 1 3

出力例 1Copy

Copy
Yes

11 と人 22 は共に 11 回目の舞踏会に参加しています。

22 と人 33 は共に 22 回目の舞踏会に参加しています。

11 と人 33 は共に 33 回目の舞踏会に参加しています。

以上よりどの二人も少なくとも 11 回同じ舞踏会に参加したので、答えは Yes です。


入力例 2Copy

Copy
4 2
3 1 2 4
3 2 3 4

出力例 2Copy

Copy
No

11 と人 3311 回も同じ舞踏会に参加していないので、答えは No です。

Score : 200200 points

Problem Statement

There are NN people numbered 1,2,,N1,2,\ldots,N.

MM parties were held. kik_i people attended the ii-th (1iM)(1\leq i \leq M) party, and they were People xi,1,xi,2,,xi,kix_{i,1},x_{i,2},\ldots,x_{i,k_i}.

Determine if every two people attended the same party at least once.

Constraints

  • 2N1002\leq N \leq 100
  • 1M1001\leq M \leq 100
  • 2kiN2\leq k_i \leq N
  • 1xi,1<xi,2<<xi,kiN1\leq x_{i,1}<x_{i,2}<\ldots < x_{i,k_i}\leq N
  • All values in the input are integers.

Input

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

NN MM
k1k_1 x1,1x_{1,1} x1,2x_{1,2} \ldots x1,k1x_{1,k_1}
\vdots
kMk_M xM,1x_{M,1} xM,2x_{M,2} \ldots xM,kMx_{M,k_M}

Output

Print Yes if every two people attended the same party at least once; print No otherwise.


Sample Input 1Copy

Copy
3 3
2 1 2
2 2 3
2 1 3

Sample Output 1Copy

Copy
Yes

Both Person 11 and Person 22 attended the 11-st party.

Both Person 22 and Person 33 attended the 22-nd party.

Both Person 11 and Person 33 attended the 33-rd party.

Therefore, every two people attended the same party at least once, so the answer is Yes.


Sample Input 2Copy

Copy
4 2
3 1 2 4
3 2 3 4

Sample Output 2Copy

Copy
No

Person 11 and Person 33 did not attend the same party, so the answer is No.



2025-04-17 (Thu)
22:18:55 +00:00