Car Workshops
InterviewTime limit1sMemory limit512 MB
Cars pass through workshops in order and each one repaints color a to b on a match, so compute every final color.
- Level
Medium5 of 10
- Topics
- Simulation, Array
- Solved
- No attempts yet
Problem
In Byteland (Bajtocja) there is only one road connecting the east with the west. It passes through exactly cities, and in each of them there is a car workshop that can repaint a car. Every workshop runs a promotion under which it repaints a car of color into color for free (here is the number of the city along the road, ). Each workshop chooses these two colors independently, and every workshop has exactly one such promotion.
A convoy of cars set off from the east toward the west. The drivers in Byteland are very frugal, but they also like to freshen up their cars. For this reason every driver tries to repaint their car in each successive city, but does so only when it is free. In other words, at a given workshop a car is changed to color only if its current color is exactly .
Knowing the initial colors of all the cars, determine their colors after they reach the west. Assume the road is one-way, that is, the cars move only from east to west.
Input
The first line contains three integers , , and () separated by single spaces, denoting respectively the number of cars, the number of cities, and the number of possible car colors. The colors are numbered from to .
The second line contains integers () separated by single spaces, denoting the initial colors of the successive cars.
Each of the next lines describes the workshops visited in order along the route. Each such description consists of two integers and () separated by a single space, meaning that the workshop in the -th city repaints a car of color into color for free.
Output
In the first and only line print integers, separated by single spaces, denoting the colors of the successive cars after they reach the west.
Hint
Walkthrough of the sample. At the first workshop the second and fifth cars (color ) are repainted, so the sequence of colors becomes 1 4 3 4 4. At the second workshop only the first car (color ) changes, giving 2 4 3 4 4. Finally, at the third workshop the second, fourth, and fifth cars (color ) are repainted, so the final sequence of colors is 2 1 3 1 1.