#P15089. [UOI 2025 II Stage] OldPost --- NewPost
[UOI 2025 II Stage] OldPost --- NewPost
题目描述
In the country of Trilyandia, there are cities connected by roads. The road system in this country is special:
- one road connects only two different cities;
- there can be at most one road between any two cities;
- from any city, it is possible to reach any other city, possibly passing through others.
The postal company OldPost decided to provide delivery services in this country. Due to the limited number of staff, transportation is carried out only along one route of length , that is, a sequence of cities such that
- for ();
- cities and are connected by a road .
To maximize profit, OldPost decided to operate along the route with the maximum length.
An ancient competitor of OldPost --- NewPost decided to do the same, but along its own route : , which does not necessarily differ from , but also has the maximum possible length.
The president, upon learning about the intentions of both companies, asked OldPost and NewPost to choose routes and in such a way as to cover the maximum number of cities (that is, to ensure that the maximum number of cities are in at least one route). Since the president of Trilyandia specializes in management, while the postal companies specialize in delivering items rather than finding routes, you have been tasked with finding such and .
Note that each company wants to have the maximum possible length of its route; even if choosing a shorter route increases the total number of cities covered.
Help find routes and that have the maximum possible length and cover the maximum number of cities.
输入格式
The first line contains a single integer --- the number of cities in the country.
Each of the next lines contains two integers and --- pairs of cities between which there is a road.
输出格式
The first line should contain a single integer () --- the length of the found trade routes.
The second line should contain integers () --- the cities in route .
The third line should contain integers () --- the cities in route .
If there are multiple optimal routes, output any of them.
10
1 2
2 3
3 4
4 5
2 6
6 7
3 8
8 9
10 1
6
5 4 3 2 1 10
9 8 3 2 6 7
提示
:::align{center}
:::
In the example, the longest possible routes are as follows:
- -----
- -----
- -----
- -----
The first and fourth routes allow covering all cities.
Scoring
- ( points): ;
- ( points): ;
- ( points): ; there is exactly one city that is directly connected to all others;
- ( points): ; there are exactly two cities that are connected to only one other city (the cities form a line);
- ( points): ; there is exactly one city that is connected to three or more cities;
- ( points): ; there are no more than cities that are connected to only one other city;
- ( points): ;
- ( points): ;
- ( points): no additional restrictions.