0164. Royal Federation

Имя входного файла: royal.in
Имя выходного файла: royal.out
Ограничение по времени: 2 s
Ограничение по памяти: 32 megabytes

The king of Fooland has recently decided to reorganize his kingdom. Inspired by the democracy processes in neighbouring countries, he decided to convert his kingdom into Royal Federation. The Royal Federation would consist of several provinces, each headed by its governor.

There are N cities in his kingdom, numbered from 1 to N. Some cities are connected by roads. Roads are designed in such a way, that for each city there is exactly one way to get to any other city by the roads, not passing through any city more than once.

To prevent wastes for maintaining too small provinces, each province must contain at least B cities. However, to keep governments effective, each province must contain at most 3B cities.

Each province must have its governer headquaters in some city. This city may be outside the province itslef, but one must be able to get to the city with governer headquaters of his province in such a way, that all intermediate cities that he visits on his way belong to his province (and only the terminal city may be from another province).

One city may contain headquaters for several provinces.

Help the king to see his plans fulfilled.

Input file

The first line of the input file contains two integer numbers – N and B (1 ≤ N ≤ 10,000, 1 ≤ B ≤ N). Next N-1 lines contain descriptions of roads, each line contains two integer numbers – the cities the road connects.

Output file

If it is impossible to fulfil king's plans of reorganization, output 0 on the first line of the output file. In the other case output K – the number of provinces in your plan of the Royal Federation. After that output N integer numbers ranging from 1 to K – for each city output the number of the province it belongs to.

Finally output K integer numbers – the cities where the capitals of the provinces must be located in,

Examples:

royal.inroyal.out
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


Источник: Petrozavodsk Summer 2003. Final Contest, Saturday, August 30
Автор: Andrew Stankevich

Обсудить       Отправить решение