QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 1024 MB Total points: 100 Hackable ✓

#14506. 木林森

Statistics

小Wは木が好きです。ある日、彼女は夢の中で $n$ 個の頂点からなる木を構成し、その木から $m$ 個の連結成分を選んで記録しました。しかし、夢から覚めると、彼女は夢の中の木の構造を忘れてしまい、連結成分の情報も曖昧になってしまいました。確かなことは、これらの連結成分のサイズがすべて $k$ 以下であるということだけです。彼女は記憶を頼りに、紙にこれら $m$ 個の連結成分に対応する頂点集合を書き出しました。これらの $m$ 個の頂点集合がすべてある木の連結成分となり得るような木が存在するかどうか、彼女に教えてあげてください。

入力

1行目に3つの正整数 $n, m, k$ ($1 \le n, m \le 10^4, 2 \le k \le 20$) が与えられます。これらはそれぞれ、元の木の頂点数、頂点集合の数、頂点集合のサイズの最大値を表します。

続く $m$ 行には、それぞれいくつかの正整数が含まれます。各行の最初の正整数 $s_i$ ($2 \le s_i \le k$) は対応する頂点集合のサイズを表し、それに続いて $s_i$ 個の互いに異なる正整数が、その頂点集合に含まれる頂点を表します。

出力

1行で文字列を出力してください。条件を満たす木が存在する場合は YES を、存在しない場合は NO を出力してください(大文字と小文字は区別しません)。

入出力例

入力 1

5 3 3
3 1 2 3
3 2 3 4
3 5 2 1

出力 1

YES

入力 2

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

出力 2

NO

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.