Dimensional Tree Trip
Time limit1sMemory limit1024 MB
Given a tree, find the longest sequence of distinct vertices where each step moves to a vertex not adjacent to the current one, counting the start as a warp.
- Level
Medium7 of 10
- Topics
- Tree, Dynamic programming, Graph
- Solved
- No attempts yet
Problem
A tree with vertices and edges is given. Moving to a vertex that is not directly connected to the current vertex by an edge is called a warp. Each vertex can be visited at most once. Find the maximum number of possible warps. The starting vertex can be chosen freely, and choosing the starting vertex also counts as a warp.
Input
The first line contains . The next lines each contain an edge in the form , , meaning vertex and vertex of the tree are connected by an edge.
Output
Print the maximum number of possible warps on the first line.
Constraints