Venn Intervals

아직 제출이 없습니다시간 제한3초메모리 제한1024 MB

문제

A Venn interval diagram is a graphical way to illustrate intersections of sets in 1D, similar to the more familiar Venn diagrams in 2D. A Venn interval diagram is defined by assigning a non-zero-length integer interval \[l_i,u_i)\[l\_i , u\_i) to each set S_iS\_i. The regions where different intervals overlap correspond to intersections of different combinations of the sets (see Figure N.1).

Figure N.1: Venn interval diagram corresponding to Sample Input 1. The intervals assigned to each of the six sets AA through FF are shown at the top; the regions encoded by the diagram are labeled along the number line. This Venn interval diagram has nine regions, and is not degenerate (since no interval is contained in any other.)

More formally, given the interval assigned to each set, you can compute the regions that appear in the Venn interval diagram with the following algorithm:

  • Combine together all of the interval starting points l_il\_i and ending points u_iu\_i into a single set, and sort them to get an integer sequence p_1<p_2<<p_mp\_1 < p\_2 < \cdots < p\_m.
  • Label each interval (p_j,p_j+1)(p\_j , p\_{j+1}) spanning consecutive pp values with all the sets S_iS\_i for which (p_j,p_j+1)(p\_j , p\_{j+1}) is contained within \[l_i,u_i)\[l\_i , u\_i). (Note that partial overlaps are not possible: the pp-interval is either contained within, or disjoint from, each set-interval).
  • The set of all non-empty labels are the regions of the Venn interval diagram. Each label S_a,S_b,\\{S\_a, S\_b, \dots \\} represents an intersection of sets S_aS_bS\_a ∩ S\_b ∩ \cdots.

In the example Venn interval diagram shown above, there are six sets (AA through FF) and nine regions (BB, ABA ∩ B, AA, ACA ∩ C, ACDA ∩ C ∩ D, CDC ∩ D, DD, EE, and FF). This example Venn interval diagram has a “hole” where no sets overlap (between the end of region DD and the start of EE); this is allowed. Note also that EFE ∩ F is not a region: EE and FF’s intervals touch at their endpoints, but the two do not overlap on a pp-interval.

Not every list of regions has a corresponding illustration as a Venn interval diagram. Consider for example the regions ABA ∩ B, BCB ∩ C, and CAC ∩ A. There is no way to lay out intervals for AA, BB, and CC on the real line to form exactly these three regions (any Venn interval diagram that includes these three regions must also include ABCA ∩ B ∩ C). In addition, a Venn interval diagram is degenerate if any interval is contained within another interval: if l_il_jl\_i ≤ l\_j and u_ju_iu\_j ≤ u\_i for some iji \ne j. For example, if CC’s right endpoint were at 44 instead of 55, the Venn interval diagram in Figure N.1 would become degenerate, since the interval assigned to the set CC would then be contained within AA’s interval (corresponding to Sample Input 3).

Given a list of regions, construct a non-degenerate Venn interval diagram containing exactly those regions, if possible.

입력

The first line of the input contains a single integer nn, the number of regions required in your diagram (1n4,0001 ≤ n ≤ 4\\,000). The next nn lines each describe one region. Each line begins with an integer kk, the number of sets that intersect to form the region (1k2,0001 ≤ k ≤ 2\\,000), followed by kk space-separated set names. Each set name contains only lowercase or uppercase letters (a-z, A-Z) and no set name is longer than ten characters. All set names listed on the same line are distinct, and no two regions list the exact same collection of set names. No more than 2,0002\\,000 unique set names appear in total across all regions.

출력

If a non-degenerate Venn interval diagram does not exist whose regions match the input, print IMPOSSIBLE and produce no further output.

Otherwise, print the intervals describing any one valid diagram. For each set name that appears in the input, print a line of output starting with that set name, followed by two space-separated integers ll and rr: the left and right endpoints of the interval assigned to that set name in your diagram. The endpoints must satisfy 106l<u106-10^6 ≤ l < u ≤ 10^6. You may list the sets in any order, but every set name that appears in the input must correspond to exactly one line of output.

Every region in the input must appear at least once in your Venn interval diagram, and your diagram must not contain any regions other than those specified in the input. You diagram must not be degenerate: no interval should be enclosed inside another.