Divide and Conquer
Time limit8sMemory limit512 MB
Split the cities of a connected graph into three independent sets where two of them have equal size, and list all achievable equal sizes.
- Level
Hard8 of 10
- Topics
- Graph, Divide and conquer, Dynamic programming, Greedy
- Solved
- No attempts yet
Problem
Taro, Hanako, and Jiro rule the kingdom of JAG as a group of three. The kingdom of JAG has cities, and some pairs of cities are connected by bidirectional roads. From any city, every other city is reachable by traversing one or more roads.
One day Taro and Hanako finally fell out, and the three decided to divide the cities among themselves and rule. But they became so hostile that Taro even hates the situation where a city he rules is directly connected by a single road to a city Hanako rules. So they decided to divide the cities to be ruled so that the following conditions hold.
- Any pair consisting of a city ruled by Taro and a city ruled by Hanako is not directly connected by a road. This is because Taro and Hanako get along extremely badly.
- Cities ruled by the same person are also not directly connected by a road. This is to encourage diplomacy by forcing them to route through cities under someone else's rule even in such a situation.
- The total number of cities ruled by Taro and the total number of cities ruled by Hanako must be equal. This is because if the totals were not equal, Taro and Hanako would likely get along even worse. Here, Jiro is very broad-minded, so the total number of cities ruled by Jiro may be anything.
If the division satisfies the above conditions, the three can agree and rule, and they will not complain even if someone rules 0 cities. At this time, write a program that lists all possible values of the total number of cities ruled by Taro (= the total number of cities ruled by Hanako).
Input
The input consists of multiple datasets. The number of datasets is at most 50. Each dataset is given in the following format.
N M
u1 v1
...
uM vM
The first line contains two integers () and (), representing the number of cities and the number of roads, respectively. Among the following lines, the -th line contains two integers and (), representing that the -th road connects city and city bidirectionally. It is guaranteed that from any city, every other city is reachable by traversing one or more roads. Also, multiple roads connecting the same pair of cities are not given. That is, for all , holds.
The end of the input is represented by a line consisting of two zeros.
Output
For each dataset, when there are possible values for the total number of cities ruled by Taro, first output on the first line, then output the possible totals one per line in ascending order.