#P2325. [SCOI2005] 王室联邦
[SCOI2005] 王室联邦
Description
The king of the country of the “Yu” people (Yu) plans to reorganize his nation. He wants to divide the country into several provinces, each governed by a member of their royal federation.
There are cities, numbered .
Some cities are connected by roads. Between any two distinct cities, there is exactly one simple path (direct or indirect).
To avoid overly fragmented management, each province must contain at least cities.
For effective governance, each province may contain at most cities.
Each province must have a capital. The capital may be located inside the province or outside it.
However, for any city in the province, all cities on the path to the capital (except the last city, i.e., the capital itself) must belong to that province.
A city may serve as the capital for multiple provinces.
Please help the king.
Input Format
The first line contains two integers .
The next lines each describe an edge, with two integers giving the indices of the two cities connected by this road.
Output Format
If it is impossible to satisfy the king’s requirements, output .
Otherwise, on the first line output an integer , the number of provinces in your partition.
On the second line, output integers. The -th number is the index of the province to which city belongs. Each index must be in .
On the third line, output integers, the city indices of the capitals of these provinces.
If multiple solutions exist, you may output any of them.
8 2
1 2
2 3
1 8
8 7
8 6
4 6
6 5
3
2 1 1 3 3 3 3 2
2 1 8
Hint
For of the testdata, .
Thanks to
Translated by ChatGPT 5
京公网安备 11011102002149号