Pipe cleaning
Time limit7sMemory limit256 MB
Decide whether a subset of pipes covers every pipe crossing with exactly one of the two crossing pipes chosen.
Problem
The water utility of Linköping draws groundwater from several wells outside the city. Each pipe runs in a straight line from one well to a point in the city.
All pipes lie at the same depth, so two pipes that meet create a junction at that spot. Exactly two pipes meet at any junction. A well does not count as a junction, and a well may start zero or more pipes.
Debris builds up at junctions, strains the pipes, and eventually opens a sinkhole. The company that runs the water supply designed a cleaning robot to stop that. When a robot is inserted at a well into one pipe, it travels that pipe to the end and back, cleaning every junction on the pipe. To keep two robots from colliding, the rules say that at each junction where two pipes meet, only one of those two pipes may contain a robot.
The water supply is shut off while cleaning runs, so the company wants to finish in one pass. Decide whether robots can be inserted into some subset of the pipes at the same time so that every junction is cleaned and the rule holds.
Input
The first line contains the number of wells and the number of pipes . (, )
Each of the next lines contains and , the coordinates of well . () The wells are numbered 1 through in that order.
Each of the next lines contains three integers , , . (, ) This means a pipe starts at well and ends at the point .
The only well a pipe passes through is its own starting point. Every point where three or more pipes meet is a well. Two pipes share at most one point, and that point may be an endpoint of a pipe. Every pipe has positive length.
Output
Print possible on one line if such a subset exists, and impossible otherwise.