King's Puzzle
Time limit3sMemory limit1024 MB
Build a connected simple graph on n vertices whose degrees take exactly k distinct values, or report NO if that is impossible.
- Level
Medium6 of 10
- Topics
- Greedy, Implementation, Math
- Solved
- No attempts yet
Problem
King Kendrick is the sovereign ruler of the Kotlin Kingdom, which has cities. He is preparing for the next government session, and the cities must be connected by bidirectional roads. Four ministries have set requirements:
- Ministry of Transport and Digital Infrastructure: All cities must be connected, so there is a path between any two cities.
- Ministry of Environment: No loop road is allowed, so no road may connect a city to itself.
- Treasury Department: There may be at most one road between any pair of cities.
- Ministry of ICPC: If is the number of roads connected to city , then the set must consist of exactly distinct numbers.
King Kendrick has trouble with the ICPC Ministry's requirement and asks for help. Find any set of roads that meets all four requirements, or report that it is impossible.
Input
The only line contains two integers and ().
Output
If it is impossible to meet all requirements, print NO on a single line.
Otherwise, print YES on the first line. On the second line, print the number of roads (). Then print lines, each with two integers and (), the two cities connected by a road.