QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 512 MB Total points: 100 Hackable ✓

#12818. 构建图

Statistics

对于一个包含 $n$ 个节点和 $m$ 条边的无向图 $G$,我们可以定义距离 $dist(i, j)$ 为节点 $i$ 和 $j$ 之间最短路径的长度。路径的长度等于路径中边的数量。如果 $i$ 和 $j$ 之间没有路径,我们令 $dist(i, j)$ 等于 $n$。

然后,我们可以定义图 $G$ 的权值 $w_G$ 为 $\sum_{i=1}^n \sum_{j=1}^n dist(i, j)$。

现在,给定 $n$ 个节点,初始时没有任何边。我们将选择不超过 $m$ 对节点 $(i, j)$ ($i \neq j$),并为每一对选定的节点添加一条边。通过这种方式,我们可以得到一个包含 $n$ 个节点且边数不超过 $m$ 的无向图 $G$。

你的任务是求出构造完成后 $w_G$ 的最小值。

输入格式

输入的第一行包含两个整数 $n$ 和 $m$ ($1 \le n \le 10^6, 1 \le m \le 10^{12}$)。

输出格式

输出一行,包含一个整数:$w_G$ 的最小值。

样例

样例输入 1

4 5

样例输出 1

14

说明

在样例中,我们可以选择添加边 $(1, 2), (1, 4), (2, 4), (2, 3)$ 和 $(3, 4)$。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.