Logo
(追記) (追記ここまで)

30480번 - Elevated Profits 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB81353253.333%

문제

Marina, a digital influencer who loves traveling the world, is embarking on a promotional tour for a women’s clothing brand called W2M (From Woman to Woman Marina). Marina’s journey takes her through $N$ cities in Latin America, each with its unique charm, and identified with a distinct integer from 1ドル$ to $N,ドル called its popularity index.

To facilitate Marina’s travels, W2M has provided her with $N - 1$ transfers, connecting pairs of cities in a way that guarantees accessibility to all $N$ cities. Marina can traverse these connections as many times as she pleases.

Marina’s mission is to showcase the brand’s dresses in each of the $N$ cities, with a twist. Each time she visits a city for the first time, she must select a dress she hasn’t worn before and capture the city’s essence in a social media post. Every new picture she shares attracts followers, creating anticipation for the next one. The anticipation value for her first picture is 1ドル,ドル and it increments by 1ドル$ for each subsequent picture.

Marina can revisit any city as often as desired, but a new picture must only be posted on her initial visit to a city. Her goal is to maximize the profit of her tour, which is computed as the sum of the anticipation value of each picture multiplied by the popularity index of the city where the picture is taken. More precisely, let $p_i$ be the popularity index of the city where the $i$-th picture is taken. With this information, the profit can be calculated as

$$\sum_{i=1}^{N}{i \times p_i} = 1 \times _1 + 2 \times p_2 + \cdots + N \times p_N$$

Now, Marina seeks your assistance. Given that the tour has to start in city $p_1 = R,ドル your task is to help Marina determine the maximum profit she can achieve by strategically planning the order of her city visits.

입력

The first line contains two integers $N$ (1ドル ≤ N ≤ 3 \times 10^5$) and $R$ (1ドル ≤ R ≤ N$), indicating respectively the number of cities and the initial city of the tour.

Each of the next $N - 1$ lines contains two integers $U$ and $V$ (1ドル ≤ U, V ≤ N$ and $U \ne V$), indicating that there is a transfer between cities $U$ and $V$. It is guaranteed that it is possible to reach every city by using the transfers.

출력

Output a single line with an integer indicating the maximum profit Marina can achieve on her promotional tour.

제한

예제 입력 1

7 3
3 5
3 7
5 1
5 4
7 2
7 6

예제 출력 1

121

예제 입력 2

1 1

예제 출력 2

1

힌트

출처

ICPC > Regionals > Latin America > Latin America Regional Contests > Latin America Regional Contests 2023 E번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /