#P8595. 「KDOI-02」一个网的路

    ID: 9428 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划 DP贪心2022洛谷原创O2优化树形 DP

「KDOI-02」一个网的路

Background

“{&%#~!@ovo} (They also have a road network? Interesting.)”
“{&%#@~akoio!@} (Finish the work you should do first. We will talk about those distracting toys later.)”
“{!%_&#%@yw?} (Is your Chinese language not good?)”
Under the blue sky, people still do not know that danger is coming.

Problem Description

The hostile civilization has been angered. They want to destroy Earth’s road network in a strange way. Earth’s road network can be approximated as a forest with nn nodes and mm undirected edges. They want to use the following 22 operations:

  • Destroy all roads connected outward from a city uu.
  • Build a new road between cities u,vu, v.

They want to change Earth’s road network into the least efficient form: a single chain (path). Now you want to know: to achieve the goal, what is the minimum number of operations they need?

Input Format

Read input from standard input.

The first line contains 22 positive integers n,mn, m.

The next mm lines each contain 22 positive integers u,vu, v, indicating there is an undirected road between cities u,vu, v.

Output Format

Write output to standard output.

Output one line containing one integer, which is the minimum number of operations the aliens need.

3 1
1 2
1
见附件中的 traffic2.in
见附件中的 traffic2.ans
见附件中的 traffic3.in
见附件中的 traffic3.ans

Hint

Sample Explanation

  • Sample 1 Explanation:
    Initial graph:

    Apply operation 2 to cities 2,32, 3.

    Now it has become a chain.

Constraints

For 100%100\% of the testdata, 0m<n2×1060 \le m < n \le 2 \times 10^6, and the input is guaranteed to be valid.

Test Point ID nn \le Special Property
121\sim2 1010 A
363\sim6 500500 None
787\sim8 10410^4 A
99 B
101210\sim12 None
131513\sim15 10610^6
162016\sim20 2×1062\times10^6
  • Special Property A: Each connected component is guaranteed to be a binary tree.
  • Special Property B: The degree of each vertex is guaranteed to be at most 22.

Hint

This problem has a large I/O size, so a faster I/O method is recommended.

Translated by ChatGPT 5