Maximum Clique of an Interval Graph
Time limit1sMemory limit512 MB
Given N intervals, find a largest set of pairwise overlapping intervals, and output its size plus the vertex indices in lexicographically smallest order.
Problem
In graph theory a clique is a subgraph that is complete. That is, it is a set of vertices in which every two vertices are joined by an edge. A maximum clique is a largest such set. Finding a maximum clique in a general graph is NP-hard.
You are given intervals. Interval starts at and ends at , and two intervals overlap when they share at least one point. These intervals define an interval graph. The interval graph has vertices, and vertex and vertex are joined by an edge exactly when interval and interval overlap. If the two intervals do not overlap, there is no edge between the two vertices.
For example, when the intervals are , , , , the interval graph looks like this.

The maximum clique of this interval graph is .

Given intervals, find a maximum clique of their interval graph.
Input
The first line has the number of intervals (). Each of the next lines has two integers and , the start point and the end point of interval , separated by a space. ()
Output
Print the size of a maximum clique on the first line. On the second line print the vertex numbers of that clique in increasing order, separated by spaces. If the graph has more than one maximum clique, print the one whose increasing list of vertex numbers is lexicographically smallest.