H. 2025夏-A-3 Linear Component

    传统题 400ms 64MiB

2025夏-A-3 Linear Component

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

题目描述

A component of an undirected graph GG is a maximum connected sub-graph of GG. A linear component is a component that has a linear structure property-- that is, each vertex in that component has exactly one previous vertex (except the first one), and one next vertex (except the last one). The size of a linear component is the number of edges in the component.

Now given an undirected graph, you are supposed to find the largest size of its linear components.

输入格式

Each input file contains one test case, which first gives 2 positive integers: nn (104\le 10^4), the number of vertices, and mm (5n\le 5n), the number of edges.

Then mm lines follow, each describes an edge in the form u v, where u and v are the indices of the two ends of the edge. The vertices are indexed from 1 to nn. It is guaranteed that no duplicated edges are given.

输出格式

For each case, print in a line the number and the largest size of the linear components. The numbers must be separated by a space. If there is no linear component, the maximum size is defined to be 1-1.

样例

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

限制

对于所有的测试用例,限制为400 ms, 64 MB

PAT2025夏季重现赛

未参加
状态
已结束
规则
IOI
题目
9
开始于
2025-7-13 14:00
结束于
2025-7-13 17:30
持续时间
3.5 小时
主持人
参赛人数
45