Wi-Fi Network
Time limit1sMemory limit128 MB
Decide whether a point in an open square sees all two or three computers through straight segments that cross none of up to 100 walls.
- Level
Hard8 of 10
- Topics
- Geometry, Brute force
- Solved
- No attempts yet
Problem
Hektor came up with an idea to make himself rich. He decided to write a program that solves the well-known problem of placing a Wi-Fi router so that every computer in an apartment can reach it, meaning the shortest route connecting the router to a computer does not pass through any wall.
The first version of the program is heavily simplified: it handles only apartments with at most three computers, and the router has unlimited range. Because the range is unlimited, the shortest route from the router to a computer is simply the straight segment between them, so a computer is reachable exactly when that straight segment does not cross any wall.
Can you write such a program? For each test set decide whether at least one spot for the router exists from which every computer is reachable.
Input
The first line contains the number of test sets (). The test sets follow.
The first line of each set contains three integers , , (, , ). The area searched for the router is limited to points with and . Here is the number of computers and is the number of walls in the area.
The next lines each contain two integers , (, ), the position of a computer.
The next lines each contain four integers , , , (each strictly between and ), describing the segment from to that represents one wall.
You may assume that no two walls cross, although they may share endpoints. No computer lies on a wall.
Output
For each test set print TAK if the router can be placed so that its signal reaches every computer without passing through a wall, and NIE otherwise. Print each answer on its own line.