#P8028. [COCI 2021/2022 #3] Cijanobakterije
[COCI 2021/2022 #3] Cijanobakterije
Description
A microbiologist has cyanobacteria. Among these bacteria, there are pairs , meaning there is a biological chain between and . Several biological chains can be connected one after another to form a long chain. The length of a long chain is defined as the number of bacteria on that long chain.
Now you may add some biological chains between pairs of bacteria, such that after adding, the entire set of biological chains contains no cycles.
After performing some add-chain operations, find the maximum possible length of the longest long chain.
Input Format
The first line contains two integers .
The next lines each contain two positive integers , indicating that there is a biological chain between bacteria and . The data guarantees that , and the same biological chain appears at most once. Also, these biological chains contain no cycles.
Output Format
Output the length of the longest long chain.
100 0
100
8 6
1 2
1 3
1 4
5 6
5 7
5 8
6
6 5
1 2
2 3
3 4
4 6
4 5
5
Hint
[Sample 2 Explanation]
After adding a biological chain between and , the longest long chain is , with length .
[Constraints and Notes]
This problem uses bundled subtasks.
- Subtask 1 (15 pts): .
- Subtask 2 (6 pts): .
- Subtask 3 (6 pts): .
- Subtask 4 (15 pts): .
- Subtask 5 (28 pts): No special restrictions.
For of the testdata, , , .
[Hints and Explanation]
Translated from COCI 2021-2022 CONTEST #3 Task 2 Cijanobakterije.
The score of this problem follows the original COCI problem, with a full score of .
Translated by ChatGPT 5
京公网安备 11011102002149号