Homework

각 학생의 기온 배열은 바로 앞 학생의 배열에서 한 위치만 바꾼 것이며, m개의 배열을 사전순으로 정렬하고 같으면 번호가 작은 학생을 앞에 둔다.

어려움8문자열 매칭정렬해시맵DFS아직 제출이 없습니다시간 제한20초메모리 제한512 MB

문제

Mrs Byterina, a teacher in the Elementary School no. 64 in the East Bitshire, gave the following homework to her pupils recently. The children had to note temperature for the nn next days, and collect the results afterwards to write them in a row.

Unfortunately, the day before the deadline of the homework, it turned out that only Alina diligently performed the task. Kate, a friend of Alina, asked her to share her results. Alina reluctantly agreed, but she ordered Kate to change results a bit, so that they did not look the same. So Kate copied Alina's results, except of one of them, which she made up by herself (Kate did not bother to check whether the temperature that she made up was actually different than that collected by Alina, well...). Next, Wojtek copied the results from Kate, and again made up exactly one of the results by himself. Matthew copied from Wojtek, Martin from Matthew, Lidia from Martin, and so on. In the end, all pupils had their very own results!

Mrs Byterina has just collected homeworks of the whole class. She has decided that she will grade the results at home and now she will just organize them. She would like to order them in the lexicographical order -- a homework AA should be placed before BB if at the leftmost position where these homeworks differ, the temperature in the homework AA is lower than that in the homework BB.

In what order Mrs Byterina should put the homeworks?

입력

The first line of the input contains two integers n,mn, m (1n500,0001 \le n \le 500\\,000, 2m500,0002 \le m \le 500\\,000) denoting the number of days for which the children measured the temperature and the number of pupils, respectively. The children are numbered 11 through mm.

The next line contains nn integers t_1,,t_nt\_1, \dots, t\_n -- the consecutive measurements performed by Alina. We assume that Alina has number 11 (0t_i1090 \le t\_i \le 10^9).

Each of the next m1m - 1 lines contains two integers p_i,x_ip\_i, x\_i (1p_in1 \le p\_i \le n, 0x_i1090 \le x\_i \le 10^9); the ii-th of these rows denotes that a person i+1i + 1 copied their results from the person ii, changing the data from the p_ip\_i-th day to x_ix\_i.

출력

You should output exactly one line containing mm space-separated integers -- the order of the homeworks after organizing them. Specifically, if the ii-th of these numbers is equal to u_iu\_i, this denotes that the homework of the child u_iu\_i is the ii-th in the order after organizing the homeworks.

If two children have handed the same results, the homework of the child with a smaller number should appear earlier in the sought order.