Universal Cup Judging System

Universal Cup

حد الوقت: 1.0 s حد الذاكرة: 512 MB مجموع النقاط: 100 قابلة للهجوم ✓
الإحصائيات

有一个 $n \times m$ 的网格迷宫。为方便起见,我们定义 $(x, y)$ 为第 $x$ 行第 $y$ 列的网格。

最初,所有网格都是空的。Alice 想要设计这个迷宫,她将在网格中放置 $k$ 个墙壁。每个墙壁表示为 $x_1, x_2, y$,这意味着对于所有的 $x_1 \le i \le x_2$,$(i, y)$ 将成为该墙壁的一部分,且不能通过。除了墙壁所在的网格,其他所有网格都是空的。Alice 确保在放置 $k$ 个墙壁后,所有空网格保持连通,且迷宫中至少有一个空网格。此外,保证不同的墙壁之间没有公共网格。

现在,Alice 想知道,是否任意一对空网格之间都只有一条简单路径相连?

如果你不熟悉“简单路径”的定义,这里是它的定义: 连接空网格 $(x_s, y_s)$ 和 $(x_d, y_d)$ 的简单路径定义为一个网格位置序列 $S = \{(x_1, y_1), (x_2, y_2), \dots, (x_{len}, y_{len})\}, (len \ge 2)$,满足以下条件:

  • $(x_1, y_1) = (x_s, y_s), (x_{len}, y_{len}) = (x_d, y_d)$
  • $\forall 1 \le i \le len, 1 \le x_i \le n, 1 \le y_i \le m$
  • $\forall 1 \le i \le len, (x_i, y_i)$ 是一个空网格
  • $\forall 1 \le i \le len - 1, |x_i - x_{i+1}| + |y_i - y_{i+1}| = 1$
  • $\forall 1 \le i < j \le len, (x_i, y_i) \neq (x_j, y_j)$

如果任意两个不同的空网格 $(x_s, y_s), (x_d, y_d)$ 之间都有且仅有一条简单路径相连,输出 “YES”。否则,输出 “NO”。

输入格式

第一行包含三个整数 $n, m, k (1 \le n, m \le 10^9, 1 \le k \le 10^5)$,分别表示行数、列数和墙壁的数量。

接下来的 $k$ 行,每行包含三个整数 $x_1, x_2, y (1 \le x_1 \le x_2 \le n, 1 \le y \le m)$,表示迷宫中放置的一堵墙。

保证每对空网格之间至少有一条简单路径相连。

输出格式

输出一个字符串表示答案,即 “YES” 或 “NO”。

样例

输入格式 1

5 3 2
2 5 1
1 4 3

输出格式 1

YES

输入格式 2

5 3 1
2 4 2

输出格式 2

NO

输入格式 3

2 4 2
2 2 1
1 1 4

输出格式 3

NO

说明

样例解释展示了 Alice 的迷宫,其中黄色方块代表墙壁,白色方块代表空网格。

  1. 在第一个样例中,我们可以观察到无论选择哪个起点和终点,都只有一条简单路径。
  2. 在第二个样例中,选择 $(1, 1)$ 作为起点,$(5, 1)$ 作为终点。$S_1 = \{(1, 1), (2, 1), (3, 1), (4, 1), (5, 1)\}$ 和 $S_2 = \{(1, 1), (1, 2), (1, 3), (2, 3), (3, 3), (4, 3), (5, 3), (5, 2), (5, 1)\}$ 是两条不同的简单路径。
  3. 在第三个样例中,选择 $(1, 2)$ 作为起点,$(2, 3)$ 作为终点。$S_1 = \{(1, 2), (1, 3), (2, 3)\}$ 和 $S_2 = \{(1, 2), (2, 2), (2, 3)\}$ 是两条不同的简单路径。

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.