#B4164. Doomsday Towers and Aether Energy Transportation
Doomsday Towers and Aether Energy Transportation
Doomsday Towers and Aether Energy Transportation
On a distant planet, there are (n) doomsday towers. Each tower releases (n) different types of aether energy. For the (k)-th type of energy, it must be transported through a one‐way pipe to the (k)-th tower in order to be completely suppressed.
You are granted the power to build one‐way pipes between any two towers. Your task is to design a network of pipes such that for every pair (i, j) with (1 \le i, j \le n), if tower (i) produces the (j)-th type of energy, it will be transported to tower (j) through the pipe network. However, if the energy is consecutively transported through more than two pipes (i.e. a path of length greater than 2), the released energy will emit rays that cause mass mind control, and your mission will fail.
Determine whether there exists a pipelining scheme that meets the requirements. If yes, output (YES) and any one valid design; if no, output (NO).
Note: Direct transportation (a single pipe) or transportation via one intermediate tower (two pipes) is allowed, but no path with more than two pipes may be used. For (i=j), no transportation is needed.
inputFormat
The input consists of a single integer (n) ((1 \le n \le 10^5)), representing the number of doomsday towers.
outputFormat
If a valid design exists, output (YES) on the first line. Then, output an integer (m) representing the number of pipes in your design. Each of the following (m) lines should contain two integers (u) and (v), indicating a one‐way pipe from tower (u) to tower (v).
If no valid design exists, simply output (NO).
sample
1
YES
0
</p>