Solution
Firstly, let’s set a fallible device;
Let the ordered edges of MST be e1, e2, ..., em
, for the largest edge em: (a-b)
, we make a, b
to be Super-Point;
This greedy device is erroneous, e.g., the MST is a---(10)---b---(1)---c---(7)---d
,
k
=
3
k = 3
k=3, firstly, in a-b
, we set a, b
Super-Point; when we arrive at c-d
,
k
=
1
k = 1
k=1 can not eliminate this edge 7
, so the answer is 7
. The correct device is make a, b, d
(b
can be replaced to c
) to Super-Point; then for c
, it can c -> b
to arrive at b
, once a point arrived a Super-Point, then it can go to everywhere costless; so answer is 1
;
It is very important to comprehend this problem, especially understand the nature of Super-Point;
Given you a totally connected undirected graph
G
G
G (contains
n
∗
(
n
−
1
)
/
2
n * (n-1) / 2
n∗(n−1)/2 undirected edges)
The goal is to make every pair of points to be accessible; suppose the answer is
D
D
D, i.e., all edges can be used are
≤
D
\leq D
≤D, or you can imagine that a graph
G
1
G1
G1 consists of
n
n
n points and with all edges are
≤
D
\leq D
≤D.
There are two cases for the accessibility of two points:
1
a -> ... -> b
where every edge belongs to
G
1
G1
G1
2
a -> ... s -> b
where
s
s
s is a Super-Point, then every edge in
.
.
.
...
... is
≤
D
\leq D
≤D; it is vital to realize that s -> b
is costless i.e., once you arrived at a Super-Point, then you can go to any point with no cost;
Therefore, due to the existence of Super-Point,
G
1
G1
G1 maybe not connected graph;
Lets discuss by cases:
+
if
k
=
0
k = 0
k=0 that is no Super-Point, then
G
1
G1
G1 must be a connected-graph,
D
D
D be the maximal edge in
G
1
G1
G1; to make
D
D
D as small as possible, (according to the property of MST, i.e., a MST is
a
1
≤
a
2
≤
.
.
.
a1 \leq a2 \leq ...
a1≤a2≤..., for any ST is
b
1
≤
b
2...
b1 \leq b2 ...
b1≤b2..., then we have
b
i
≥
a
i
bi \geq ai
bi≥ai, as a lemma, the maximal edge in MST must be the least value among that in all ST), we just to make
G
1
G1
G1 be the MST of
G
G
G;
+
If
k
≥
n
k \geq n
k≥n, all points are Super-Point, there could be no edges in
G
1
G1
G1, so the answer is
0
0
0.
+
Now,
k
∈
[
1
,
n
)
k \in [1, n)
k∈[1,n), let all Super-Points be
s
1
,
.
.
.
,
s
k
s1, ..., sk
s1,...,sk; Let
s
1
,
.
.
.
,
s
k
s1, ..., sk
s1,...,sk also denotes a set, initially the set of
s
i
si
si has only one point
s
i
si
si.
.
Let us only focus on all Normal-Points (non-Super-Point)
a
1
,
a
2
,
.
.
.
a1, a2, ...
a1,a2,..., if the distance of
a
i
,
a
j
ai, aj
ai,aj is
≤
D
\leq D
≤D, then we connect a edge between them; after this process, all isolated points
a
1
,
a
2
,
.
.
.
a1, a2, ...
a1,a2,... originally will become a graph consists of several connected-sub-graphs and all edges are
≤
D
\leq D
≤D.
For any sub-graph
S
G
SG
SG (it’s connected, and consists of
a
i
ai
ai), we reduce it to be a ST (Spanning-Tree) (that will not affect the connection). Due to the goal of this problem, there must exists a edge
(
a
,
b
)
w
(a,b) w
(a,b)w where
a
∈
S
G
a \in SG
a∈SG,
b
b
b is a Super-Point and
w
≤
D
w \leq D
w≤D (only this is satisfied,
S
G
SG
SG can only reach to any other point); such a edge maybe not unique, we can just choose one. Then, we connected a edge between
(
a
,
b
)
(a,b)
(a,b) for all
S
G
SG
SG; as a result, every
S
G
SG
SG belongs to a unique root
s
i
si
si. Finally, it becomes a graph in which there exists a Tree rooted by
s
i
si
si; in other words, the graph consists of
k
k
k connected-sub-graphs where every sub-graph is also a Tree (i.e., we can add
k
−
1
k - 1
k−1 additional edges to make it to be a ST of
G
G
G)
Now, you can imagine that there are
k
k
k points
s
1
,
.
.
.
,
s
k
s1, ..., sk
s1,...,sk in
G
G
G, every point is also a independent Spanning-Tree
S
T
i
STi
STi with all edges
≤
D
\leq D
≤D.
The cost is the maximal edge in the graph (
m
a
x
(
m
a
x
(
S
T
1
)
,
m
a
x
(
S
T
2
)
,
.
.
.
)
)
max( max(ST1), max( ST2), ...))
max(max(ST1),max(ST2),...)))
Because it corresponds to a partition of the ST of
G
G
G (or you can say that it is a sub-graph of ST of G), that is, if we remove
k
−
1
k - 1
k−1 edges of the ST of
G
G
G, then it becomes such a graph; (the cost equals to the maximal edge in the graph)
Let the ordered sequence of a ST is
e
0
,
e
1
,
.
.
.
e
n
−
2
e0, e1, ... e_{n-2}
e0,e1,...en−2, we need to remove
k
−
1
k - 1
k−1 edges, of course, we should remove the maximal
k
−
1
k - 1
k−1 edges, the new maximal edge is
e
n
−
1
−
k
e_{n-1-k}
en−1−k; now, it becomes
k
k
k sub-STs, the cost
m
a
x
(
m
a
x
(
S
T
i
)
)
max( max(STi))
max(max(STi)) equals
e
n
−
1
−
k
e_{n-1-k}
en−1−k;
Due to the property of ST: if MST is
a
1
≤
a
2
,
.
.
.
a1 \leq a2, ...
a1≤a2,..., then any ST will be
b
1
≤
b
2...
b1 \leq b2 ...
b1≤b2... where
b
i
≥
a
i
bi \geq ai
bi≥ai; Therefore,
e
n
−
1
−
k
e_{n-1-k}
en−1−k in MST must
≤
\leq
≤ that in any other ST;
Code
mst.Work();
sort( Paths.begin(), Paths.end());
double ans;
if( k == 0){
ans = *Paths.rbegin();
}
else if( k >= n){
ans = 0;
}
else{
ans = Paths.at( Paths.size() - 1 - (k - 1));
}