#P8439. Altale (Fan-made FTR 7)

    ID: 9317 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>贪心洛谷原创O2优化基环树洛谷月赛

Altale (Fan-made FTR 7)

Background

Why is the rating 7?

Powerless: Equilibrium FTR 9.

Problem Description

The little robot is fishing for stars again.

The stars in the sky form several constellations. Each constellation has a “center point”. If a star loses its direct or indirect connection to the center point, then the star will detach from the constellation and fall to the ground.

After observing day and night, the little robot found the following properties of these constellations: each constellation is connected internally, and the number of connections among stars is always equal to the number of stars in that constellation.

Also, there are no connections between different constellations. Any two stars in the same constellation are connected directly or indirectly.

By observing celestial motion, he numbered the stars. He found that the center point of each constellation is the star with the smallest index in that constellation.

Unfortunately, the little robot can only obtain keys to remove these connections in a purely random way (diao yuan, “by fate”).

The little robot is very greedy and wants to get as many stars as possible in as little time as possible.

He wants kk stars. Can you tell him the minimum number of keys he needs to fish up?

If you solve this problem, maybe the little robot will give you some stars~

Simplified statement

Input Format

The first line contains two integers n,kn,k, representing the total number of stars in the sky, the total number of connections between stars, and the number of stars the little robot wants to obtain.

Next, there are nn lines. Each line contains two integers u,vu,v, indicating that there is a connection between star uu and star vv.

It is guaranteed that within any constellation, the number of connections equals the number of stars. There are no self-loops, and there will not be two connections between the same pair of stars.

Output Format

Output one integer in a single line, representing the minimum number of keys the little robot needs to obtain enough stars.

4 1
1 2
2 3
3 1
1 4
1
17 9
1 2
1 6
1 3
3 4
4 5
5 6
6 7
8 10
10 9
10 11
11 12
11 13
13 14
14 8
15 13
8 16
16 17
3

Hint

This problem uses bundled tests.

Suppose there are ll constellations in total.

For 100%100\% of the testdata, it is guaranteed that 1n106,1knl1\le n\le 10^6,1\le k\le n-l.

Subtask 1: For 20%20\% of the testdata, it is guaranteed that n1000n\le 1000.

Subtask 2: For 10%10\% of the testdata, it is guaranteed that l5l\le 5.

Subtask 3: For 20%20\% of the testdata, it is guaranteed that l15l\le 15.

Subtask 4: No additional constraints.


Sample explanation 11:

It is enough to remove the connection (1,4)(1,4).

Sample explanation 22:

It is enough to remove the three connections (8,14),(8,10),(8,16)(8,14),(8,10),(8,16).

It can be proven that there is no way with fewer removals.

There may be other ways that also require removing only 33 connections.

Translated by ChatGPT 5