Back to the Future
Time limit2sMemory limit512 MB
Given a graph of compatible pairs, find the largest vertex subset where each chosen vertex has at least A neighbors and at least B non-neighbors inside the subset.
- Level
Hard8 of 10
- Topics
- Graph, Greedy, Implementation, Queue
- Solved
- No attempts yet
Problem
Doctor Emmet is building a safer time travel device. He has collected different rare pieces of metal. Some pairs of pieces are compatible with each other. He keeps a list of all compatible pairs, and any pair that is not on the list is incompatible.
For the device to work, he must choose a set of metals. Inside that set, every chosen piece has to be compatible with at least other chosen pieces. To keep the device balanced, every chosen piece also has to be incompatible with at least other chosen pieces.
More metal means more energy and a safer device. Find the size of the largest set that satisfies both requirements.
Input
The first line contains four integers , , and separated by spaces. is the number of metal pieces (), is the number of compatible pairs (), and and are the two values described above (). The metals are numbered from to .
Each of the next lines contains two integers and describing a compatible pair (, ). No pair is given twice.
Output
Print, on one line, the size of the largest set of metals that satisfies both requirements. If no such set exists, print .