CF212E.IT Restaurants

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Сity N. has a huge problem with roads, food and IT-infrastructure. In total the city has nn junctions, some pairs of them are connected by bidirectional roads. The road network consists of n1n-1 roads, you can get from any junction to any other one by these roads. Yes, you're right — the road network forms an undirected tree.

Recently, the Mayor came up with a way that eliminates the problems with the food and the IT-infrastructure at the same time! He decided to put at the city junctions restaurants of two well-known cafe networks for IT professionals: "iMac D0naldz" and "Burger Bing". Since the network owners are not friends, it is strictly prohibited to place two restaurants of different networks on neighboring junctions. There are other requirements. Here's the full list:

  • each junction must have at most one restaurant;
  • each restaurant belongs either to "iMac D0naldz", or to "Burger Bing";
  • each network should build at least one restaurant;
  • there is no pair of junctions that are connected by a road and contains restaurants of different networks.

The Mayor is going to take a large tax from each restaurant, so he is interested in making the total number of the restaurants as large as possible.

Help the Mayor to analyze the situation. Find all such pairs of (a,b)(a,b) that aa restaurants can belong to "iMac D0naldz", bb restaurants can belong to "Burger Bing", and the sum of a+ba+b is as large as possible.

输入格式

The first input line contains integer nn (3<=n<=5000)(3<=n<=5000) — the number of junctions in the city. Next n1n-1 lines list all roads one per line. Each road is given as a pair of integers xi,yix_{i},y_{i} (1<=xi,yi<=n)(1<=x_{i},y_{i}<=n) — the indexes of connected junctions. Consider the junctions indexed from 1 to nn .

It is guaranteed that the given road network is represented by an undirected tree with nn vertexes.

输出格式

Print on the first line integer zz — the number of sought pairs. Then print all sought pairs (a,b)(a,b) in the order of increasing of the first component aa .

输入输出样例

  • 输入#1

    5
    1 2
    2 3
    3 4
    4 5
    

    输出#1

    3
    1 3
    2 2
    3 1
    
  • 输入#2

    10
    1 2
    2 3
    3 4
    5 6
    6 7
    7 4
    8 9
    9 10
    10 4
    

    输出#2

    6
    1 8
    2 7
    3 6
    6 3
    7 2
    8 1
    

说明/提示

The figure below shows the answers to the first test case. The junctions with "iMac D0naldz" restaurants are marked red and "Burger Bing" restaurants are marked blue.

首页