Time Planner

Time limit1sMemory limit128 MB

Summary
Given each of up to 20 members' busy intervals, output every maximal window of length at least one hour where at most one member is absent throughout.
Level

Medium7 of 10

Topics
Intervals, Sorting, Implementation, Simulation
Solved
No attempts yet

Problem

Problems in computer science are often grouped into classes (NP, NP-complete, unsolvable, and so on). Whatever class of problems a team has to solve, there is always one recurring problem: finding a time when all the programmers can meet to work together on their project.

Given every member's busy calendar, your task is to write a program that finds every possible meeting window for the team.

Input

The first line contains the number of scenarios.

Each scenario begins with a line containing the number of team members mm (2≤m≤202 \le m \le 20). For each team member, there is a line with the number of calendar entries nn (0≤n≤1000 \le n \le 100), followed by nn lines in this format:

YYYY MM DD hh mm ss YYYY MM DD hh mm ss some string here

Each line gives the year, month, day, hour, minute, and second of both the start and the end of an appointment, followed by a description string. All numbers are zero-padded to the width shown and separated by single spaces. The description may contain spaces and is at most 100 characters long. All dates lie between January 1, 1800 (midnight) and January 1, 2200 (midnight). For simplicity, assume every month has exactly 30 days, and no invalid date (such as January 31) ever occurs.

Note that the end time of an appointment is the moment the member becomes free again and is ready to join a meeting.

Output

For each scenario, first print a line Scenario #i:, where ii is the scenario number starting from 1. Then print one line for every possible meeting window, where a valid meeting satisfies all of the following:

  • at every moment of the meeting, at least two team members are present;
  • at every moment of the meeting, at most one team member is absent;
  • the meeting lasts at least one hour;
  • all team members are willing to work 24 hours a day.

For example, with three members A, B, and C, this is a valid meeting: it begins with only A and B; later C joins, and before it ends A may leave.

Always print the longest possible window that satisfies these conditions, even if it is as long as 400 years. Sort the lines by date and time, using this format:

appointment possible from MM/DD/YYYY hh:mm:ss to MM/DD/YYYY hh:mm:ss

The month, day, year, hour, minute, and second must be zero-padded to the required width. If no meeting is possible, print a single line containing no appointment possible. Separate the output of consecutive scenarios with a blank line.

Examples2

  1. Example 1

    Input
    2
    3
    3
    2002 06 28 15 00 00 2002 06 28 18 00 00 TUD Contest Practice Session
    2002 06 29 10 00 00 2002 06 29 15 00 00 TUD Contest
    2002 11 15 15 00 00 2002 11 17 23 00 00 NWERC Delft
    4
    2002 06 25 13 30 00 2002 06 25 15 30 00 FIFA World Cup Semifinal I
    2002 06 26 13 30 00 2002 06 26 15 30 00 FIFA World Cup Semifinal II
    2002 06 29 13 00 00 2002 06 29 15 00 00 FIFA World Cup Third Place
    2002 06 30 13 00 00 2002 06 30 15 00 00 FIFA World Cup Final
    1
    2002 06 01 00 00 00 2002 06 29 18 00 00 Preparation of Problem Set
    2
    1
    1800 01 01 00 00 00 2200 01 01 00 00 00 Solving Problem 8
    0
    
    Expected output
    Scenario #1:
    appointment possible from 01/01/1800 00:00:00 to 06/25/2002 13:30:00
    appointment possible from 06/25/2002 15:30:00 to 06/26/2002 13:30:00
    appointment possible from 06/26/2002 15:30:00 to 06/28/2002 15:00:00
    appointment possible from 06/28/2002 18:00:00 to 06/29/2002 10:00:00
    appointment possible from 06/29/2002 15:00:00 to 01/01/2200 00:00:00
    
    Scenario #2:
    no appointment possible
    
  2. Example 2

    Input
    1
    2
    0
    0
    
    Expected output
    Scenario #1:
    appointment possible from 01/01/1800 00:00:00 to 01/01/2200 00:00:00