PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#DSU0000027. Phiên dịch ngôn ngữ (Interpretation)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Phiên dịch ngôn ngữ (Interpretation)

Interpretation

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

A festival has NN participants and uses MM languages numbered from 11 to MM. Participant ii knows KiK_i distinct languages, listed in the input.

Two people can communicate directly if they share at least one language. They may also exchange information indirectly through one or more intermediaries: each intermediary only needs a shared language with the preceding person and a possibly different shared language with the next person. The entire chain need not speak a single common language.

Determine whether information can be passed between every pair of participants through direct communication or a chain of intermediaries. Every participant knows at least one listed language.

Input

The first line contains N,MN,M. Each of the following NN lines starts with KiK_i, followed by exactly KiK_i language IDs.

Output

Print YES if all participants can communicate, otherwise print NO.

Subtasks

  • Subtask 1 (20 points): 2≤N≤302\le N\le30, 1≤M≤301\le M\le30, ∑Ki≤100\sum K_i\le100; 1≤Ki≤M1\le K_i\le M; each person’s language IDs are distinct and lie in [1,M][1,M].
  • Subtask 2 (30 points): 2≤N≤10002\le N\le1000, 1≤M≤10001\le M\le1000, ∑Ki≤5000\sum K_i\le5000; 1≤Ki≤M1\le K_i\le M; each person’s language IDs are distinct and lie in [1,M][1,M].
  • Subtask 3 (50 points): 2≤N≤1052\le N\le10^5, 1≤M≤1051\le M\le10^5, ∑Ki≤105\sum K_i\le10^5; 1≤Ki≤M1\le K_i\le M; each person’s language IDs are distinct and lie in [1,M][1,M].

Examples

Input

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

Output

YES

Explanation

Participants 1 and 2 share language 2, participants 2 and 3 share language 4, and participants 3 and 4 share language 6. Thus everyone belongs to one communicating group.