Xayahh-Rakann at Moloco (Easy)
Time limit2sMemory limit512 MB
Given n jars and inseparable pairs, decide if exactly k jars can be kept so that no inseparable pair is split across the two groups.
- Level
Easy3 of 10
- Topics
- Brute force, Graph, Bit manipulation
- Solved
- No attempts yet
Problem
Moloco is an IT company, but a few of its employees have been running forbidden experiments on two kinds of unstable dark matter. They named the two kinds Xayahh-Rakann after an old legend about a couple who cannot be separated.
The employees produced units of unstable dark matter. Each unit sits in its own jar, and the jars are labeled 1 through .
After many experiments they found that certain pairs of jars must not be placed far apart. If such a pair is separated, the matter becomes unstable enough to explode and wipe out the planet. Those pairs are called inseparable pairs, and the employees identified of them. Every other pair is safe at any distance.
A renovation is scheduled for the building that currently stores the jars. The employees will keep exactly jars in the basement, which the renovation does not touch, and move the other jars to a new office far from that building. If the two jars of an inseparable pair end up in different buildings, they explode.
Decide whether the jars can be split into a group of size and a group of size safely.
Input
The first line contains three integers , , and . (, , )
Each of the next lines contains the labels of the two jars that form one inseparable pair. The two integers on a line are different and lie between 1 and . Line describes the th inseparable pair. The same pair may be given more than once, and may be larger than .
Output
Print SAFE on the first line if the jars can be split safely into a group of jars and a group of jars. Otherwise print DOOMED.