#P7013. [CERC2013] History course
[CERC2013] History course
题目描述
You are to give a series of lectures on important historical events, one event per lecture, in some order. Each event lasted for some time interval We say that two events are related if their intervals have a common point. It would be convenient to schedule lectures on related events close to each other. Moreover, lectures on unrelated events should be given in the order in which the events have taken place (if an event A preceded an unrelated event , then the lecture on A should precede the lecture on .
Find the minimum integer and an order of the lectures such that any two related events are scheduled at most lectures apart from each other (lectures number and are considered to be lectures apart).
输入格式
The first line of input contains the number of test cases . The descriptions of the test cases follow:
The first line of each test case contains the number . Each of the next lines contains two integers and - the ends of the i-th interval. The intervals are pairwise different.
输出格式
Print the answers to the test cases in the order in which they appear in the input. The first line of the answer to each test case should contain the minimum value of . The next lines should list the intervals (in the same format as in the input) in an order such that any two related events are scheduled at most lectures apart. Remember to put any unrelated intervals in the proper order!
题目大意
给定 个区间,第 个区间为 。你需要把这些区间按某种顺序排列,使得两个区间如果没有交点,则左端点更小的区间需要排在前面。
设第 个区间排在第 个位置,定义区间 与 之间的距离为 。令 为任意两个相交的区间之间的最大距离,你需要最小化 ,并输出一组对应的合法顺序。
对于 的数据,满足 ,。
1
3
1 6
2 3
4 5
1
2 3
1 6
4 5
提示
Time limit: 10 s, Memory limit: 128 MB.
感谢 hht2006 提供的 Special Judge。