Tree and paths of length two
Time limit2sMemory limit512 MB
Decide whether some tree on N nodes has exactly S simple paths of length 2.
- Level
Medium4 of 10
- Topics
- Tree, Combinatorics, Greedy
- Solved
- No attempts yet
Problem
Given and , write a program that decides whether a tree satisfying both of the following conditions exists.
- The tree has nodes.
- The number of simple paths of length 2 is .
A simple path is a path that does not pass through the same vertex more than once. The length of a path is the number of edges on it, so a simple path of length 2 joins three distinct vertices.
Direction does not matter in a path. A-B-C and C-B-A count as the same path.
Input
The first line contains and separated by a space. (, )
Output
Print 1 if such a tree can be built, and 0 if it cannot.