아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

King's Puzzle

시간 제한3초메모리 제한1024 MB

요약
n개 정점으로 이루어진 연결된 단순 그래프에서 차수의 서로 다른 값이 정확히 k개가 되도록 간선을 구성하거나 불가능함을 판별한다.
난이도

보통10점 중 7점

유형
그래프, 그리디, 수학
정답자
아직 제출이 없습니다

문제

King Kendrick is a sovereign ruler of Kotlin Kingdom. He is getting ready for the next session of the government. Kotlin Kingdom consists of nn cities. These cities need to be connected by several bidirectional roads. Since ministries are responsible for aspects of safety and comfort of the kingdom's residents, some of them have made the following requirements:

  • "All the cities should be connected by new roads, i.e. there should be a path from any city to any other city via the roads" --- Ministry of Transport and Digital Infrastructure.
  • "There may not be a loop road --- a road that connects a city with itself" --- Ministry of Environment.
  • "There should be at most one road between a pair of cities" --- Treasury Department.
  • "If a_ia\_i is the number of roads connected to ii-th city, then the set a_1,…,a_n\\{a\_1, \ldots, a\_n\\} should consist of exactly kk distinct numbers" --- Ministry of ICPC.

King Kendrick has issues with the requirements from the Ministry of ICPC. He asks you to help him. Find any set of roads that suits all the requirements above or say that it is impossible.

입력

The only line of the input consists of two integers nn and kk (1≤k≤n≤5001 \le k \le n \le 500).

출력

If it is impossible to satisfy all the requirements, output "NO" in the only line.

Otherwise, output "YES" in the first line.

Output mm --- the number of roads (0≤m≤n⋅(n−1)20 \le m \le \frac{n \cdot (n - 1)}{2}) in the second line.

Next mm lines should contain pairs of integers aa and bb --- the cities to connect by a road (1≤a,b≤n1 \le a, b \le n).

예제2

  1. 예제 1

    입력
    5 2
    
    예상 출력
    YES
    4
    1 2
    1 3
    1 4
    1 5
    
  2. 예제 2

    입력
    4 1
    
    예상 출력
    YES
    4
    1 2
    2 3
    3 4
    4 1