Submit | All submissions | Best solutions | Back to list |
WAR - Art of War |
The Warring States Period (473-22l BC) refers to the centuries of turmoil following the Spring and Autumn Period. China was divided into many little kingdoms that were constantly fighting with each other. Unlike in previous ages, when chivalry played an important role in battles and the states fought mostly for balance of power or to resolve disputes, in this period the aim of battle was to conquer and completely annihilate the other states. Eventually seven states, known as the ``Seven Great Powers'' rose to prominence: Qi, Chu, Yan, Han, Zhao, Wei, and Qin. After numerous alliances and counter-alliances, Qin defeated all the other states one by one, putting an end to the Warring States Period.
You are given a map that shows the position of the capital for each state, and the borders between the states as a series of line segments. Your job is to determine which states were fighting with each other. This is pretty easy to determine - if two states had a common border, then they were fighting.
Input
The input contains several blocks of test cases. Each case begins with a line containing two integers: the number 1<= n <=600 of states, and the number 1<= m <= 4000 of border segments. The next n lines describe the coordinates of capitals, there are two integers in each line. The next m lines after that describe the m border segments. Each line contains four integers x1, y1, x2 and y2 meaning that there is a border segment from (x1, y1) to (x2, y2).(It is not given in the input what the two states on the two sides of the border are, but it can be deduced from the way the borders go.)
Each state is enclosed by a continuous borderline. The states are surrounded by an infinite wasteland, thus a border segment either separates two states, or a state from the wasteland. It is not possible that the same state is on both sides of a border segment, or the wasteland is on both sides of a border segment. There is exactly one capital in each state, and there is no capital in the wasteland. The border segments do not cross each other, they can meet only at the end points.
The input is terminated by a block with n = m = 0.
Output
For each test case, you have to output n lines that describe the enemies of the n states (recall that if two states share a border, then they are enemies). Each line begins with an integer, the number x of enemies the given state has. This number is followed by x numbers identifying the enemies of the state. These numbers are between 1 and n and number 1 refers to the first capital appearing in the input, number n refers to the last.
Example
Input: 4 12 3 2 11 8 12 17 1 19 0 0 10 0 10 0 20 0 20 0 20 10 20 10 20 20 20 20 10 20 10 20 0 20 0 20 0 10 0 10 0 0 10 0 10 10 0 10 10 10 20 10 10 10 10 20 10 10 4 16 170 13 24 88 152 49 110 130 60 60 140 60 140 60 140 140 140 140 60 140 60 140 60 60 0 0 200 0 200 0 200 200 200 200 0 200 0 200 0 0 40 40 160 40 160 40 160 160 160 160 40 160 40 160 40 40 20 20 180 20 180 20 180 180 180 180 20 180 20 180 20 20 0 0 Output: 2 2 4 2 1 3 2 2 4 2 1 3 1 2 2 1 3 2 2 4 1 3
Added by: | Fudan University Problem Setters |
Date: | 2008-04-19 |
Time limit: | 5s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: C99 ERL JS-RHINO NODEJS PERL6 VB.NET |
Resource: | ACM Central European Programming Contest 2004(unofficial test data) |
hide comments
2010-08-13 23:24:37 gustav
A good thing to notice is that it is expected that the output sequence for each town is sorted... It took me quite some time to figure that out... |