#P2325. [SCOI2005] 王室联邦

    ID: 1303 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>搜索2005四川各省省选Special Judge深度优先搜索,DFS

[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 NN cities, numbered 1N1\ldots N.

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 BB cities.

For effective governance, each province may contain at most 3×B3\times B 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 N,BN,B.

The next N1N-1 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 00.

Otherwise, on the first line output an integer KK, the number of provinces in your partition.

On the second line, output NN integers. The II-th number is the index of the province to which city II belongs. Each index must be in [1,K][1,K].

On the third line, output KK integers, the city indices of the capitals of these KK 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 100%100\% of the testdata, 1BN1031\le B\leq N\le 10^3.

Thanks to

/user/9433
ing the spj.

Translated by ChatGPT 5