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

19071번 - Build the Graph 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB82292942.029%

문제

For an undirected graph $G$ with $n$ nodes and $m$ edges, we can define the distance $\textit{dist} (i, j)$ as the length of the shortest path between nodes $i$ and $j$. The length of a path is equal to the number of edges in the path. If there is no path between $i$ and $j,ドル we set $\textit{dist} (i, j)$ equal to $n$.

Then, we can define $w_G,ドル the weight of the graph $G,ドル as $\sum_{i = 1}^n \sum_{j = 1}^n \text{dist} (i, j)$.

Now, given $n$ nodes and no edges initially, we will choose no more than $m$ pairs of nodes $(i, j)$ ($i \neq j$) and add an edge between the respective nodes for every chosen pair. This way, we can get an undirected graph $G$ with $n$ nodes and no more than $m$ edges.

Your task is to find the minimal possible value of $w_G$ after such construction.

입력

The first line of the input contains two integers $n$ and $m$ (1ドル \leq n \leq 10^6,ドル 1ドル \leq m \leq 10^{12}$).

출력

Print a single line with a single integer: the minimum possible value of $w_G$.

제한

예제 입력 1

4 5

예제 출력 1

14

힌트

In the example, we can choose to add edges $(1, 2),ドル $(1, 4),ドル $(2, 4),ドル $(2, 3)$ and $(3, 4)$.

출처

Camp > Petrozavodsk Programming Camp > Summer 2017 > Day 4: Ruyi Ji Contest 2 F번

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

출처

대학교 대회

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

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