Mock CCO '19 Contest 2 Problem 3 - A Cactus Problem

View as PDF

Submit solution

Points: 15 (partial)
Time limit: 0.6s
Memory limit: 162M

Problem type

Given a cactus graph, compute the maximum distance between two vertices.

Constraints

1N5104

0M104

2Ki103

Input Specification

The first line contains two space-separated integers, N and M. There are N vertices labeled from 1 to N.

M lines follow. Each line starts with an integer Ki, followed by Ki space-separated integers. Adjacent integers in each line are connected with an edge. The graph is guaranteed to be a connected cactus.

Output Specification

Output the diameter of the graph.

Sample Input

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

Sample Output

Copy
8

Comments