
ZOJ Problem Set  2368
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. This problem contains multiple test cases! The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks. The output format consists of N output blocks. There is a blank line between output blocks. Input 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 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. Sample Input
1 Sample Output
3 Author: Andrew Stankevich Source: Andrew Stankevich's Contest #3 