CF1656F.Parametric MST

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given nn integers a1,a2,…,ana_1, a_2, \ldots, a_n. For any real number tt, consider the complete weighted graph on nn vertices Kn(t)K_n(t) with weight of the edge between vertices ii and jj equal to wij(t)=ai⋅aj+t⋅(ai+aj)w_{ij}(t) = a_i \cdot a_j + t \cdot (a_i + a_j).

Let f(t)f(t) be the cost of the minimum spanning tree of Kn(t)K_n(t). Determine whether f(t)f(t) is bounded above and, if so, output the maximum value it attains.

给你 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n。对于任意实数 tt,考虑一个具有 nn 个顶点的完全加权图 Kn(t)K_n(t),其中顶点 ii 与顶点 jj 之间的边的权重为 wij(t)=ai⋅aj+t⋅(ai+aj)w_{ij}(t) = a_i \cdot a_j + t \cdot (a_i + a_j)。

令 f(t)f(t) 表示图 Kn(t)K_n(t) 的最小生成树 的总权重。判断 f(t)f(t) 是否有上界;若存在上界,则输出其能达到的最大值。

输入格式

The input consists of multiple test cases. The first line contains a single integer TT (1≤T≤1041 \leq T \leq 10^4) — the number of test cases. Description of the test cases follows.

The first line of each test case contains an integer nn (2≤n≤2⋅1052 \leq n \leq 2 \cdot 10^5) — the number of vertices of the graph.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (−106≤ai≤106-10^6 \leq a_i \leq 10^6).

The sum of nn for all test cases is at most 2⋅1052 \cdot 10^5.

输入包含多个测试用例。第一行包含一个整数 TT(1≤T≤1041 \leq T \leq 10^4),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(2≤n≤2⋅1052 \leq n \leq 2 \cdot 10^5),表示图中顶点的数量。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(−106≤ai≤106-10^6 \leq a_i \leq 10^6)。

所有测试用例的 nn 值之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, print a single line with the maximum value of f(t)f(t) (it can be shown that it is an integer), or INF if f(t)f(t) is not bounded above.

对于每个测试用例,输出一行,包含 f(t)f(t) 的最大值(可以证明该值为整数);若 f(t)f(t) 无上界,则输出 INF。

输入输出样例

  • 输入#1

    5
    2
    1 0
    2
    -1 1
    3
    1 -1 -2
    3
    3 -1 -2
    4
    1 2 3 -4

    输出#1

    INF
    -1
    INF
    -6
    -18

输入解题思路,AI测评打分。不知道怎么写?

首页