Ramsey Theory
Time limit2sMemory limit1024 MB
Given a graph, find a clique of size l or an anticlique of size k, or report that neither exists.
- Level
Medium6 of 10
- Topics
- Graph, Backtracking, Brute force
- Solved
- No attempts yet
Problem
The map for Among Us is an undirected graph. Vertices are rooms, and edges are two-way tunnels between them. The game developer Ramsey believes a map must satisfy certain properties to make the game interesting.
The game has traitors and regular crew members. If the graph contains an -clique, meaning a set of vertices where every pair is joined by an edge, the crew members are spread across those vertices. If one of them is killed, all players in adjacent rooms rush over at once, find the killer, and punish them. Such a game is quite boring.
On the other hand, if the graph contains a -anticlique, meaning a set of vertices where no pair is joined by an edge, the traitors can stand on those vertices, lure good players there, and kill them, and they will likely go unnoticed. Ramsey believes this strategy also makes the game boring.
Write a program that finds an -clique or a -anticlique in the graph, or determines that neither exists. In that case, Ramsey promises the game will be exciting.
Input
The first line contains four integers , , , , separated by spaces: the number of vertices, the number of edges, and the sizes of the anticlique and the clique to find (; ; ).
Each of the next lines contains two integers , separated by a space: the endpoints of an edge (). All edges are distinct.
Output
If you find a set of vertices that is either a -anticlique or an -clique, print the numbers of all these vertices separated by spaces. If no such set exists, print .
Hints
The first sample is a pentagon with all five sides drawn and no diagonals. It has no triangles and no anti-triangles, so the answer is .
The second and third samples have an empty graph. In the second sample you need either an anti-edge or a 4-clique. Any two distinct numbers from 1 to 4 is a correct answer. The third sample is the reverse: you need either a 4-anticlique or an edge. Since there are no edges, the only correct answer is the set of all numbers from 1 to 4, listed in any order.
The fourth sample is a complete graph, so any four of its vertices form a clique and are a correct answer. A single vertex is always both a clique and an anticlique. Since the sample allows a 1-anticlique, any one-vertex set is also a correct answer.