시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 (추가 시간 없음) 1024 MB1512981.818%

문제

You are shopping on behalf of a company for a big upcoming event and the pesky accountants ask you to sort the items you buy according to their own rigid standards. Why you ask? Nobody knows except for the accountants.

입력

The first line of input contains two space-separated integers $1 \leq n \leq 10^5$ and $1 \leq k \leq 10^5$, indicating how many items you have bought and how many categories the accountants operate with respectively. On the second line follows $n$ space-separated strings $t_1, t_2, \ldots, t_n$, the names of the items you have bought. Some items may have been bought multiple times. On the third line follows $c$ space-separated distinct strings $c_1, c_2, \ldots, c_k$, the names of the categories in the order that the accountants require your items to be sorted.

Next follows $k$ lines, one describing each category. The $i^{\text{th}}$ such line begins with a string $s_i$, the name of the category it describes. It is followed by a positive integer $m_i$ and then $m_i$ space-separated distinct strings $t^i_1, t^i_2, \ldots, t^i_{m_i}$, the items that belong to category $s_i$.

All strings in the input consists of between $1$ and $10$ characters from the English alphabet ([A-Za-z]). It is guaranteed that each item you bought belongs to exactly one category, and that $c_1, c_2, \ldots, c_k$ is a permutation of $m_1, m_2, \ldots, m_k$. It also holds that $\sum_{i=1}^{k} m_i \leq 10^5$.

출력

On a single line, output $n$ strings representing the items you bought in sorted order according to the accountants. If there are multiple ways of sorting the items according to the requirements, output any of them.

예제 입력 1

6 3
Bucket Milk Milk Cheese Rose Drill
Groceries Flowers Hardware
Hardware 3 Bucket Drill Nail
Groceries 2 Milk Cheese
Flowers 2 Rose Tulip

예제 출력 1

Milk Milk Cheese Rose Drill Bucket

출처

Contest > Bergen Open > Bergen Open 2021 I번

  • 문제를 만든 사람: Kristoffer Æsøy, Petter Daae, Simen Hornnes, Torstein Strømme