Kinomani
InterviewTime limit4sMemory limit1024 MB
Given N film screening intervals, find the fewest members needed to cover every film with non-overlapping viewings, and list each member's films.
Problem
Bajtek and his friends started a film club. Members go to cinemas to watch various films, then meet and tell each other about the films they saw. Their accounts are so detailed that a film told this way is practically the same as watching it.
The Silver Horizons film festival is coming up. Club members will be sent to watch films so that together they see all of them. Each film at the festival is screened only once, in a fixed time interval. To count a film as watched, a member must watch it in full, from start to finish. At any moment a member can watch only one film, but a member can finish one film and start another at the same moment. Tickets are expensive, so the club wants to send as few members as possible.
Write a program that reads the number of films and the time intervals in which each film is screened, finds the smallest number of club members to send to the festival, and prints the result to standard output.
Input
The first line contains a natural number , the number of films at the festival (). The next lines describe the films, one per line. Each line has two natural numbers and () separated by a single space. They mean that the -th film is screened from minute to minute of the festival.
Output
The first line contains a natural number , the smallest possible number of members needed to watch all films. The next lines describe one way to achieve this. Line contains a natural number , the number of films watched by the -th member, followed by a space and the film numbers , separated by single spaces. Any valid assignment is accepted.