QOJ.ac

QOJ

Limite de temps : 2.0 s Limite de mémoire : 256 MB Points totaux : 100 Hackable ✓

#15170. 棋盘

Statistiques

Zag 有一个 $n \times m$ 的棋盘。但由于年代久远,棋盘的左上角位置 $(1, 1)$ 和右下角位置 $(n, m)$ 已经损坏。

现在 Zag 想知道是否存在一条路径,能够恰好经过所有剩下的 $n \times m - 2$ 个格子各一次。当且仅当两个格子至少有一条公共边时,我们才能从一个格子移动到另一个格子。如果存在这样的路径,请输出该路径,否则声明其不存在。

输入格式

输入包含两个整数 $n, m$ ($2 \le n, m \le 1000$),表示棋盘的大小。

输出格式

如果存在合法的路径,第一行输出 YES,在接下来的 $n \times m - 2$ 行中,每行输出一个坐标,其中第 $i + 1$ 行表示路径经过的第 $i$ 个位置的坐标。如果有多条满足条件的路径,输出任意一条即可。

如果不存在,输出 NO

样例

输入样例 1

2 2

输出样例 1

NO

输入样例 2

3 2

输出样例 2

YES
1 2
2 2
2 1
3 1

说明

本题的输出量较大,因此您应该使用较快的输出方法。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.