Ben and his $$$N$$$ groupmates, numbered from $$$1$$$ to $$$N$$$, are collaborating on a heavy school project that consists of $$$M$$$ tasks, numbered from $$$1$$$ to $$$M$$$. To complete the project efficiently and meet the project deadline, Ben decides to assign the $$$M$$$ tasks to his $$$N$$$ groupmates. For each task $$$i$$$ ($$$1 \leq i \leq M$$$), there is exactly one groupmate who will be the Person-in-Charge $$$PIC_i$$$ ($$$1 \leq PIC_i \leq N$$$), responsible for ensuring the task gets done. Additionally, each task $$$i$$$ has $$$P_i$$$ "peanuters" ("花生友" in Cantonese) — groupmates who prefer to observe the progress and give comments without actively contributing.
To ensure the tasks are completed on time, Ben has to send reminder messages in the group chat, one for each task. The behavior when Ben sends a reminder for task $$$i$$$ is as follows:
Ben's goal is to maximize the number of tasks that are handled by their respective Person-in-Charge. A task is considered handled if the Person-in-Charge reads the reminder message for that task. To achieve this, Ben can carefully decide the order in which he sends reminders for the $$$M$$$ tasks. Your task is to help Ben determine the optimal order for sending reminders so that the number of tasks handled by their respective Person-in-Charge is maximized.
The first line contains two integers, $$$N$$$ and $$$M$$$, the number of groupmates and the number of tasks respectively. ($$$1 \leq N \leq 10^5$$$, $$$1 \leq M \leq 10^5$$$)
The second line contains $$$M$$$ integers, the $$$i$$$-th integer denotes $$$PIC_i$$$, the Person-in-Charge of task $$$i$$$. ($$$1 \leq PIC_i \leq N$$$)
The next $$$M$$$ lines each start with an integer $$$P_i$$$ specifying the number of peanuters of task $$$i$$$, followed by $$$P_i$$$ distinct integers denoting the peanuters of task $$$i$$$. ($$$0 \leq P_i \leq N - 1$$$, $$$0 \leq \sum_{i=1}^{m} P_i \leq 10^5$$$)
It is guaranteed that the Person-in-Charge will not be a peanuter of the same task.
The output contains a line of $$$M$$$ integers, representing the optimal order to send the reminder messages that maximizes the number of tasks that can be handled. Each task from 1 to M should appear exactly once.
3 31 3 21 201 3
2 3 1
4 51 3 4 1 22 4 301 31 31 4
4 1 2 3 5
Explanation of sample 1:
Consider a project with $$$N = 3$$$ groupmates and $$$M = 3$$$ tasks.
Ben sends reminder messages in the order $$$[2, 3, 1]$$$.
Thus, 2 tasks are handled, which is the maximum possible.
| Name |
|---|


