Desert
Time limit2sMemory limit512 MB
Assign levels from 1 to 10^9 to n points so that the listed points of each measurement are lower than the other points in its range, or report a contradiction.
- Level
Medium7 of 10
- Topics
- Graph, Topological sort, Union-find, Intervals
- Solved
- No attempts yet
Problem
The route from Bythad to Bytara crosses the sands of the Great Byteotian Desert. The trip is hard, especially because there are only wells along the route. Knowing that the prosperity of his country depends on its communication routes, the ruler of Byteotia has decided to have new wells dug along this route. The distance from Bythad to Bytara is bytemiles. At each integer multiple of a bytemile from Bythad, there is already a well, or a new one can be dug. The lower the water level is, the harder and more costly it is to dig a well.
The royal geologist Byteasar surveys the options. He has measurements from the satellite network. The satellite data do not give the water levels directly. Each measurement covers a contiguous fragment of the route and says only that, at certain points of that fragment, the water level is lower than at the remaining points. The water level at every point is between 1 and bytemeters below the surface. Help Byteasar find a possible water level at every point along the route. The satellite data may be contradictory.
Input
The first line contains three integers , , and separated by single spaces (, ), where is the number of wells, is the number of wells already dug, and is the number of satellite measurements.
Each of the next lines contains two integers and (, ). Well is bytemiles from Bythad, and the water level in it is bytemeters below the surface. The wells are given in increasing order of .
Each of the next lines contains integers , , , followed by integers (, , ). The measurement says that the water level at each of the points is strictly lower than the water level at each of the remaining integer points in . The sum of all does not exceed .
Tests worth 60% of the score satisfy . Tests worth 30% of the score have a sum of at most .
Output
If the measurements are contradictory, print NIE on the first line. Otherwise, print TAK on the first line and, on the second line, print integers from 1 to : the water levels at the successive points along the route from Bythad. If several solutions exist, print any one of them.