Graph Game
Time limit1sMemory limit1024 MB
Given N vertices, add K edges one at a time without repeating an edge or creating an odd cycle, or report that it is impossible.
- Level
Medium4 of 10
- Topics
- Graph, Math, Implementation
- Solved
- No attempts yet
Problem

Chunbae is playing a graph game. The game starts with a graph that has vertices and no edges. Players add undirected edges one at a time. Vertices are numbered from 1 to .
Each edge added must satisfy the following conditions.
- If the graph already has an edge connecting vertices and , another edge connecting and cannot be added.
- If, after adding an edge connecting and , the graph has at least one cycle with an odd number of edges, that edge cannot be added.
If Chunbae can add edges to the graph while satisfying these conditions, Chunbae wins. Otherwise, Chunbae loses.
Determine whether Chunbae can win. If so, find the edges Chunbae must add.
Input
The first line contains and separated by a space. (, )
Output
On the first line, print YES if Chunbae can win, or NO otherwise.
If Chunbae can win, print the edges Chunbae must add, one per line in the order they are added. Each line contains the two vertices that the edge connects.