541. BR Privatization
Time limit per test: 1
Memory limit: 262144
Berland Railways (BR) is about to finish their existence as public property. Privatization is approaching.
Currently, BR consists of n
stations, some pairs are connected by bidirectional roads. Between each pair of stations there is no more than one road and any road connects exactly two different stations.
Since each Berland railway network was developed independently, the topology of BR has an interesting form. BR consists of areas. Each area is a set of stations connected in a cycle in some order. Each area borders with exactly two different other areas and shares a single station with each of them. So exactly two stations in each area are shared by neighbouring areas. Thus, each station
- either belongs to one area and has two roads going from it
- or belongs to two neighbouring areas at the same time and has four roads going from it.
Since the BR form a connected network, one can say that the areas also form a single cycle of areas.
The figure below illustrates BR's possible structure.
In this case BR has 14 stations, 18 roads and consists of four areas numbered from 1 to 4:
- the first one borders with the second and the third and has four stations;
- the second one borders with the first and the fourth and has six stations;
- the third one borders with the first and the fourth and has three stations;
- the fourth one borders with the second and the third and has five stations.
Two major companies are planning to buy most of the BR stations. However the antitrust committee has its own requirements. No two stations connected by a road should belong to the same company. It frustrates the owners of the first and the second company, they may not even be able to purchase all the stations without violating this condition.
Both companies have decided to buy stations in such a way that the total number of stations purchased by both companies is maximal. If there are multiple ways for such distribution, they agree on any of them.
Help them to carry out their plans, write a program that finds the desired buying plan. Note that the information about BR is given to you as a list of stations and roads, but the information about areas is not explicitly defined.
The first line contains a pair of integers n
(6 ≤ n
; 9 ≤ m
), where n
is the number of stations, and m
is the number of roads. All stations are arbitrarily numbered from 1 to n
. Then m
lines follow, each containing a pair of integers ai
(1 ≤ ai
) and indicating the road that connects the stations with numbers ai
. The roads are given in arbitrary order.
BR consists of at least three areas, each contains at least three stations.
In the first line print non-negative integer number n1
— the number of stations to be purchased by the first company. Then n1
numbers follow — the numbers of stations to be purchased by the first company.
In the second line print non-negative integer number n2
— the number of stations to be purchased by the second company. Then n2
numbers follow — the numbers of stations to be purchased by the second company.
If there are multiple solutions, print any of them.
6 2 5 7 8 12 14
7 1 3 6 9 10 11 13
2 2 5
2 1 3
The first example corresponds to the illustration from the problem statement.