One Stroke Drawing
Time limit2sMemory limit256 MB
Decide whether given line segments form a shape drawable in one stroke without retracing any segment.
- Level
Medium4 of 10
- Topics
- Graph, Union-find
- Solved
- No attempts yet
Problem
A programmer saw an interesting shape one day. He wondered whether he could draw it on paper with a pencil in one continuous line, tried for a few minutes, and gave up. He decided to write a program that answers the question instead.
The shape is given as a collection of straight line segments listed in no particular order. Two different segments touch only at their endpoints. Determine whether the whole shape can be drawn without lifting the pencil and without going back over a segment that is already drawn.
Input
The input contains several shapes. Each shape starts with a line holding the number of segments , where . The next lines each hold four integers , , , , describing the segment from to . At most one of and is true, and .
The input ends with a shape that has . Do not process that shape.
Output
For each shape print one line: Possible if the shape can be drawn in one stroke, Impossible otherwise. Print the words without quotes.