Collateral Cleanup
Time Limit: 30 Seconds Memory Limit: 262144 KB
Remember the big fight where the Hulk and the Abomination threw each other through the buildings of Manhattan? Or the time when the Green Goblin smashed poor Spider-Man through a good half-dozen brick walls? Wow, they must have shattered those walls into a million pieces!!!
It’s great that we have superheroes to bring the villains to justice, but have you ever wondered who gets to repair all the collateral damage when they’re done? Well actually, as president of the Action Cleanup Management (ACM) corporation, your job is to do exactly that! After a big fight, you must take all the broken pieces of the walls and put them back together just as they were before the fierce battle began.
Input
An integer on the first line of the input file indicates the number of walls you must reassemble. The first line for each wall has an integer, n, indicating the number of triangular pieces the wall was broken into (2 ≤ n ≤ 1,000,000). Then, n lines of input follow, each describing a piece with six integers, x1 y1 x2 y2 x3 y3 , that correspond to the Cartesian (x, y) coordinates of the three corners of a triangle on the original wall from which the piece came. The first line describes piece 1, the next line piece 2, and so forth. The three points will always be given in a counterclockwise winding order and form a triangle of non-zero area. All coordinates lie between 0 and 109 inclusive, with the positive y direction being the “up” direction. The n pieces given will cover a rectangular region exactly, with no gaps or overlaps.
Output
For each wall, output on a single line the numbers of the pieces, separated by spaces, in an order that will allow your robot to reassemble the wall. If more than one correct solution exists, any ordering that will work is acceptable.
Sample Input
2 4 3 4 7 1 7 6 7 6 1 6 3 4 1 6 1 1 3 4 7 1 3 4 1 1 14 0 0 3 0 2 3 2 3 3 0 12 0 2 3 12 0 4 5 4 5 12 0 5 6 5 6 12 0 12 4 5 6 12 4 12 8 5 6 12 8 4 7 4 7 12 8 0 8 4 7 0 8 2 5 4 7 2 5 5 6 5 6 2 5 4 5 4 5 2 5 2 3 2 3 2 5 0 0 0 0 2 5 0 8
Sample Output
4 1 3 2 1 2 13 14 3 4 12 11 5 6 10 9 7 8Submit
Source: 2011 Pacific Northwest Region Programming Contest