Ehab’s Last Corollary

Source: Codeforces 1364D

  1. Read the problem and summarise the task requirements.

In the problem statement, it is claimed that one of the two properties always holds. This doesn’t seem obvious!

  1. Consider why at least one of the two properties must hold in any graph with at least k vertices.

Let’s narrow the scope of our search.

  1. Prove that if the claim in the question is true, then we can always find a suitable cycle or independent set among only the first k vertices of the graph.

  2. Design an algorithm to determine whether there is a cycle among the first k vertices.
  3. Analyse the time complexity of your algorithm and estimate its running time.

  4. Implement this algorithm in code.
  5. Submit your program for judging!