QUESTION? (TIME TABLE)

YOU ARE THE OWNER OF A RAILWAY SYSTEM BETWEEN n CITIES, NUMBERED BY INTEGERS FROM 1 TO n. EACH TRAIN TRAVELS FROM THE START STATION TO THE END STATION ACCORDING TO A VERY SPECIFIC TIMETABLE (ALWAYS ON TIME), NOT STOPPING ANYWHERE BETWEEN. ON EACH STATION A DEPARTURE TIMETABLE IS AVAILABLE. UNFORTUNATELY EACH TIMETABLE CONTAINS ONLY DIRECT CONNECTIONS. A PASSENGER THAT WANTS TO TRAVEL FROM CITY p TO CITY q IS NOT LIMITED TO DIRECT CONNECTIONS HOWEVER- HE or SHE CAN CHANGE TRAINS. EACH CHANGE TAKES ZERO TIME, BUT A PASSENGER CANNOT CHANGE FROM ONE TRAIN TO THE OTHER IF IT DEPARTS BEFORE THE FIRST ONE ARRIVES. PEOPLE WOULD LIKE TO HAVE A TIMETABLE OF ALL OPTIMAL CONNECTIONS. A CONNECTION DEPARTTING FROM CITY p AT A o'CLOCK AND ARRIVING IN CITY q AT B o'CLOCK IS CALLED OPTIMAL IF THERE IS NO CONNECTION THAT BEGINS IN p NOT SOONER THAN AT A, ENDS IN q NOT LATER THAN AT B, AND HAS STRICTLY SHORTER TRAVEL TIME THAN THE CONSIDERED CONNECTION. WE ARE ONLY INTERESTED IN CONNECTIONS THAT CAN BE COMPLETED DURING SAME DAY.

TASK:

WRITE A PROGRAM THAT:
. READS THE NUMBER n AND DEPARTURE TIMETABLE FOR EACH OF n CITIES FROM THE STANDARD INPUT.
. CREATES A TIMETABLE OF OPTIMAL CONNECTIONS FROM CITY 1 TO CITY n.
. WRITES THE ANSWER TO THE STANDARD OUPUT.

INPUT:

THE INPUT BEGINS WITH THE INTEGER t, THE NUMBER OF TEST CASES. THEN t TEST CASES FOLLOW.
FOR EACH TEST CASE THE FIRST LINE OF THE INPUT CONTAINS AN INTEGER n (2 <= n <= 100000). THE FOLLOWING LINES CONTAINS n TIMETABLES FOR CITIES 1,2,....,n RESPECTIVELY.
THE FIRST LINE OF THE TIMETABLE DESCRIPTION CONTAINS ONLY ONE INTEGER m. EACH OF THE FOLLOWING m LINES CORRESPONDS TO ONE POSITION IN THE TIMETABLE AND CONTAINS: DEPARTURE TIME A, ARRIVAL TIME B (A < B) AND DESTINATION CITY NUMBER t (1 <=t <=n) SEPARATED BY SINGLE SPACES. DEPARTURE TIME A AND ARRIVEL TIME B ARE WRITTEN IN FORMAT hh:mm, WHERE hh ARE TWO DIGITS REPRESENTING FULL HOURS (00 <=hh <= 23) AND mm ARE TWO DIGITS REPRESENTING MINUTES (00 <=mm <=50). POSITIONS IN THE TIMETABLE ARE GIVEN IN NON-DECREASINGING ORDER ACCORDING TO THE DEPARTURE TIMES. THE NUMBER OF ALL POSITIONS IN ALL TIMETABLES DOES NOT EXCEED 1000000.

OUTPUT:

FOR EACH TEST CASE THE FIRST LINE OF THE OUTPUT CONTAINS AN INTEGER r- THE NUMBER OF POSITIONS IN THE TIMTABLE BEING THE SOLUTION. EACH OF THE FOLLOWING r LINES CONTAINS A DEPARTURE TIME A AND AN ARRIVAL TIME B SEPARATED BY SINGLE SPACE. THE TIME FORMAT SHOULD BE LIKE IN THE INPUT AND POSITIONS IN THE TIMETABLE SHOULD BE ORDERED INCREASINGLY ACCORDING TO THE DEPARTURE TIMES. IF THERE IS MORE THEN ONE OPTIMAL CONNECTION WITH THE SAME DEPARTURE AND ARRIVAL TIME, YOUR PROGRAM SHOULD OUPUT JUST ONE.

EXAMPLE:

SAMPLE INPUT:

1
3
3
09:00 15:00 3
10:00 12:00 2
11:00 20:00 3
2
11:30 13:00 3
12:30 14:00 3
0

SAMPLE OUPUT:

2
10:00 14:00
11:00 20:00

Comments
There's no need to TYPE IN ALL CAPS
This article has been dead for over six months. Start a new discussion instead.