QOJ.ac

QOJ

시간 제한: 1 s 메모리 제한: 1024 MB 총점: 100 해킹 가능 ✓

#18704. 疫学調査

통계

2020年、新型感染症が流行し、UCPC国の疾病管理本部が疫学調査を行っている。UCPC国の人口は合計 $N$ 人であり、それぞれ $1, 2, \dots, N$ の住民番号が付けられている。

疾病管理本部は、これまでに $M$ 回の集まりがあったことを把握した。各集まりには $k$ 人が参加し、その集まりには住民番号が $a_1, a_2, \dots, a_k$ である人々が参加した。

感染症は密接かつ密閉された空間でのみ感染するため、必ず集まりの中でのみ感染する。感染症が伝播するルールは以下の通りである。

  • 集まりに参加した人々のうち、1人以上の人が感染症に感染していた場合、その集まりに参加したすべての人が感染症に感染する。
  • 集まりに感染症に感染した人がいない場合、何も起こらない。

疾病管理本部は確保した資料をもとに、初期の感染者を予測しようとしている。集まりの情報および $M$ 回の集まりが終わった後の感染者の情報が与えられたとき、最初の集まりが行われる前に感染していた人を逆追跡するプログラムを作成せよ。上記のルール以外の経路で感染症が伝播したり、感染症が治癒したりすることはないと仮定する。

入力

最初の行に人の数 $N$、集まりの数 $M$ ($2 \le N \le 100\,000, 1 \le M \le 100\,000$) が与えられる。

2行目から $M$ 行には、集まりの情報が時間順に与えられる。各行には、各集まりに参加する人の数 $k$ ($2 \le k \le N$) と、集まりに参加した人の住民番号 $a_i$ ($1 \le a_i \le N, a_i \neq a_j$) が与えられる。複数の集まりが同時に行われることはない。

最後の行には、$N$ 人の感染情報が与えられる。最後の集まりが終わった後、住民番号が $i$ である人が感染症に感染していれば $1$、そうでなければ $0$ が与えられる。感染者が一人もいない可能性があることに注意せよ。

$k$ の合計は $1\,000\,000$ を超えない。

出力

もし集まりを行う前に感染していた人を逆追跡できない場合は NO を出力する。

そうでない場合は、最初の行に YES を出力し、2行目に感染情報を意味する整数 $N$ 個を空白で区切って出力する。このうち $i$ 番目の数は、住民番号が $i$ である人が最初の集まりが始まる前に感染症に感染していた場合は $1$、そうでなければ $0$ である。可能な感染状態が複数ある場合は、そのうちのどれか一つを出力すればよい。

入出力例

入力 1

7 3
3 1 2 3
3 3 4 5
3 5 6 7
0 0 1 1 1 1 1

出力 1

YES
0 0 0 1 1 1 1

入力 2

7 3
3 1 2 3
3 3 4 5
3 5 6 7
1 0 1 0 1 0 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.