luogu#P3174. [HAOI2009] 毛毛虫

    ID: 2243 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划 DP2009河南各省省选树形 DP

[HAOI2009] 毛毛虫

Background

Thanks to @ScanfN for providing two sets of hack testdata.

Problem Description

For a tree, we can extract some path together with the edges incident to that path; it looks like a caterpillar. The more vertices it contains, the larger the caterpillar. For example, extracting part of the tree on the left (Figure 11) yields the caterpillar on the right (Figure 22).

Input Format

The first line contains two integers N,MN, M, denoting the number of vertices and the number of edges in the tree.

The next MM lines each contain two integers a,ba, b, indicating that there is an edge between vertices aa and bb (a,bNa, b \le N). You may assume that no identical pair (a,b)(a, b) appears more than once.

Output Format

Output a single integer on one line, representing the size of the largest caterpillar.

13 12 
1 2 
1 5 
1 6 
3 2 
4 2 
5 7 
5 8 
7 9 
7 10 
7 11 
8 12 
8 13 
11

Hint

For 40%40\% of the testdata, 1N500001\leq N \le 50000.

For 100%100\% of the testdata, 1N3000001\leq N \le 300000.

Translated by ChatGPT 5