CF1184E1.Daleks' Invasion (easy)

普及+/提高

通过率:0%

时间限制:6.00s

内存限制:128MB

AC君温馨提醒

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

题目描述

Heidi found out that the Daleks have created a network of bidirectional Time Corridors connecting different destinations (at different times!). She suspects that they are planning another invasion on the entire Space and Time. In order to counter the invasion, she plans to deploy a trap in the Time Vortex, along a carefully chosen Time Corridor. She knows that tinkering with the Time Vortex is dangerous, so she consulted the Doctor on how to proceed. She has learned the following:

  • Different Time Corridors require different amounts of energy to keep stable.
  • Daleks are unlikely to use all corridors in their invasion. They will pick a set of Corridors that requires the smallest total energy to maintain, yet still makes (time) travel possible between any two destinations (for those in the know: they will use a minimum spanning tree).
  • Setting the trap may modify the energy required to keep the Corridor stable.

Heidi decided to carry out a field test and deploy one trap, placing it along the first Corridor. But she needs to know whether the Daleks are going to use this corridor after the deployment of the trap.

She gives you a map of Time Corridors (an undirected graph) with energy requirements for each Corridor.

For a Corridor cc, Emax(c)E_{max}(c) is the largest e≤109e \le 10^9 such that if we changed the required amount of energy of cc to ee, then the Daleks may still be using cc in their invasion (that is, it belongs to some minimum spanning tree). Your task is to calculate Emax(c1)E_{max}(c_1) for the Corridor c1c_1 that Heidi plans to arm with a trap, which is the first edge in the graph.

海蒂发现,戴立克人已经建立了一个双向时间通道网络,连接着不同的目的地(在不同的时间点)!她怀疑他们正计划再次对整个时空发动入侵。为了阻止这次入侵,她计划在时间漩涡中部署一个陷阱,位置精心选定在某一条时间通道上。她深知摆弄时间漩涡十分危险,因此向博士咨询了具体操作方法。她获知了以下信息:

  • 不同的时间通道维持稳定所需能量各不相同;
  • 戴立克人在入侵时不太可能使用所有通道。他们将选择一组通道,使得维持该组通道所需的总能量最小,同时仍能保证任意两个目的地之间均可通行(内行人都知道:他们将采用一棵最小生成树);
  • 部署陷阱可能会改变该通道维持稳定所需的能量。

海蒂决定先进行一次实地测试,仅部署一个陷阱,并将其安置在第一条时间通道上。但她需要预先判断:在陷阱部署之后,戴立克人是否仍会使用这条通道。

她向你提供了一份时间通道地图(即一个无向图),其中每条通道都标有其维持稳定所需能量。

对于某条通道 cc,定义 Emax(c)E_{max}(c) 为满足如下条件的最大值 e≤109e \le 10^9:若将 cc 所需能量修改为 ee,则戴立克人仍可能在入侵中使用 cc(即 cc 属于某棵最小生成树)。你的任务是计算海蒂计划安放陷阱的那条通道 c1c_1(即图中第一条边)所对应的 Emax(c1)E_{max}(c_1)。

输入格式

The first line contains integers nn and mm (2≤n≤1052 \leq n \leq 10^5, n−1≤m≤106n - 1 \leq m \leq 10^6), number of destinations to be invaded and the number of Time Corridors.

Each of the next mm lines describes a Corridor: destinations aa, bb and energy ee (1≤a,b≤n1 \leq a, b \leq n, a≠ba \neq b, 0≤e≤1090 \leq e \leq 10^9).

It's guaranteed, that no pair a,b{a, b} will repeat and that the graph is connected — that is, it is possible to travel between any two destinations using zero or more Time Corridors.

第一行包含两个整数 nn 和 mm(2≤n≤1052 \leq n \leq 10^5,n−1≤m≤106n - 1 \leq m \leq 10^6),分别表示需入侵的目的地数量和时间通道(Time Corridors)的数量。

接下来的 mm 行每行描述一条时间通道:目的地 aa、bb 及所需能量 ee(1≤a,b≤n1 \leq a, b \leq n,a≠ba \neq b,0≤e≤1090 \leq e \leq 10^9)。

保证不会出现重复的无序对 {a,b}\{a, b\},且图是连通的——即任意两个目的地之间均可通过零条或多条时间通道相互到达。

输出格式

Output a single integer: Emax(c1)E_{max}(c_1) for the first Corridor c1c_1 from the input.

输出一个整数:输入中第一条走廊 c1c_1 对应的 Emax(c1)E_{max}(c_1)。

输入输出样例

  • 输入#1

    3 3
    1 2 8
    2 3 3
    3 1 4

    输出#1

    4

说明/提示

After the trap is set, the new energy requirement for the first Corridor may be either smaller, larger, or equal to the old energy requiremenet.

In the example, if the energy of the first Corridor is set to 44 or less, then the Daleks may use the set of Corridors 1,2,2,3{ { 1,2 }, { 2,3 } } (in particular, if it were set to less than 44, then this would be the only set of Corridors that they would use). However, if it is larger than 44, then they will instead use the set 2,3,3,1{ {2,3}, {3,1} }.

陷阱设置后,第一条走廊的新能量需求可能小于、大于或等于原来能量需求。

在示例中,若第一条走廊的能量设为 44 或更小,则戴立克将使用走廊集合 1,2,2,3{ { 1,2 }, { 2,3 } }(特别地,若设为小于 44,则这将是他们唯一使用的走廊集合)。然而,若该能量大于 44,则他们将改用集合 2,3,3,1{ {2,3}, {3,1} }。

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

首页