QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 1024 MB Puntuación total: 100 Hackeable ✓

#18704. Epidemiological Investigation

Estadísticas

In 2020, a new infectious disease is spreading, and the UCPC Disease Control Headquarters is conducting an epidemiological investigation. The population of UCPC consists of $N$ people, each assigned a resident registration number from $1, 2, \dots, N$.

The Disease Control Headquarters has determined that there have been $M$ gatherings so far. Each gathering involved $k$ people, and the participants had resident registration numbers $a_1, a_2, \dots, a_k$.

Since the disease is transmitted only in close, enclosed spaces, it is transmitted exclusively within gatherings. The rules for the spread of the disease are as follows:

  • If one or more people participating in a gathering were already infected with the disease, all people participating in that gathering become infected.
  • If no one participating in a gathering is infected, nothing happens.

Using the gathered data, the Disease Control Headquarters wants to predict the initial infected individuals. Given the information about the gatherings and the infection status of people after all $M$ gatherings have concluded, write a program to trace back who was infected before the first gathering. Assume that there are no cases where the disease spreads through paths other than the rules above, and that the disease is never cured.

Input

The first line contains the number of people $N$ and the number of gatherings $M$ ($2 \le N \le 100\,000$, $1 \le M \le 100\,000$).

From the second line, the information for $M$ gatherings is given in chronological order. Each line contains the number of participants $k$ ($2 \le k \le N$) and the resident registration numbers $a_i$ of the people who participated in the gathering ($1 \le a_i \le N$, $a_i \neq a_j$). No two gatherings occur at the same time.

The last line contains the infection information for the $N$ people. If the person with resident registration number $i$ is infected after the last gathering, $1$ is given; otherwise, $0$ is given. Note that there may be no infected people.

The sum of $k$ does not exceed $1\,000\,000$.

Output

If it is impossible to trace back the infected people before the gatherings, output NO.

Otherwise, output YES on the first line, and on the second line, output $N$ integers separated by spaces representing the infection status. The $i$-th number should be $1$ if the person with resident registration number $i$ was infected before the first gathering, and $0$ otherwise. If there are multiple possible infection states, you may output any one of them.

Examples

Input 1

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

Output 1

YES
0 0 0 1 1 1 1

Input 2

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

Output 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.