아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Irritating accountants

면접 대비

시간 제한3초메모리 제한1024 MB

요약
구매한 n개 항목을 분류별로 묶은 뒤, 회계사가 정한 분류 순서대로 각 분류의 항목을 출력한다. 분류 안의 순서는 임의로 정해도 된다.
난이도

보통10점 중 4점

유형
해시맵, 정렬, 구현, 배열
정답자
아직 제출이 없습니다

문제

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≤n≤1051 \leq n \leq 10^5 and 1≤k≤1051 \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 nn space-separated strings t_1,t_2,…,t_nt\_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 cc space-separated distinct strings c_1,c_2,…,c_kc\_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 kk lines, one describing each category. The ithi^{\text{th}} such line begins with a string s_is\_i, the name of the category it describes. It is followed by a positive integer m_im\_i and then m_im\_i space-separated distinct strings ti_1,ti_2,…,ti_m_it^i\_1, t^i\_2, \ldots, t^i\_{m\_i}, the items that belong to category s_is\_i.

All strings in the input consists of between 11 and 1010 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,…,c_kc\_1, c\_2, \ldots, c\_k is a permutation of m_1,m_2,…,m_km\_1, m\_2, \ldots, m\_k. It also holds that ∑_i=1km_i≤105\sum\_{i=1}^{k} m\_i \leq 10^5.

출력

On a single line, output nn 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

  1. 예제 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
    
    예상 출력
    Milk Milk Cheese Rose Drill Bucket