Polygon
Time limit1sMemory limit128 MB
Given a convex polygon and a set of non-crossing diagonals, report the largest number of sides among the pieces the diagonals divide it into.
- Level
Medium4 of 10
- Topics
- Graph, DFS, Implementation, Geometry
- Solved
- No attempts yet
Problem
You are given a convex polygon with sides, where , together with distinct diagonals that do not cross one another inside the polygon. (The only point that two distinct diagonals may share is a vertex of the polygon.) The vertices of the polygon are numbered from to counterclockwise. These diagonals split into smaller convex polygons whose interiors do not overlap.
In the figure below, the four diagonals 1-8, 8-3, 3-1, and 3-6 split the polygon into two quadrilaterals and three triangles.

Write a program that reads the description of the polygon and its diagonals from standard input, finds the largest number of sides among the polygons produced by dividing , and writes that number to standard output.
Input
Each line of the input contains two positive integers separated by a single space.
The first line contains the number of vertices and the number of diagonals .
Each of the next lines describes one diagonal as a pair of positive integers: the numbers of the two vertices that the diagonal joins.
The input is always well formed, so your program does not need to validate it.
Output
Output a single positive integer: the largest number of sides among the convex polygons produced by dividing with the given diagonals.