QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 1024 MB مجموع النقاط: 100 قابلة للهجوم ✓

#14216. Buried Treasure

الإحصائيات

一张藏宝图

埋藏的宝藏可以通过藏宝图找到。有 $m$ 个不同的地点,编号为 $1$ 到 $m$。每个地点要么包含宝藏,要么包含陷阱。

Joey 给了你 $n$ 张藏宝图。每张藏宝图有两个标记 $m_1, m_2$。对于 $i \in \{1, 2\}$,如果 $m_i < 0$,则该地图声称地点 $|m_i|$ 包含陷阱。如果 $m_i > 0$,则该地图声称地点 $|m_i|$ 包含宝藏。

如果一张藏宝图所做的声称中至少有一个是正确的,我们就称这张藏宝图是合理的(reasonable)。例如,如果一张地图声称地点 1 包含宝藏且地点 2 包含陷阱,而实际上地点 1 包含陷阱且地点 2 包含宝藏,那么这张地图就是不合理的。

Joey 声称他给你的每张藏宝图都是合理的。你能检查这是否可能吗?即是否存在一种将地点 1 到 $m$ 分配为宝藏或陷阱的方案,使得每张地图都至少做出一个正确的声称?

输入格式

输入的第一行包含两个空格分隔的整数 $n$ 和 $m$,分别表示你拥有的藏宝图数量以及藏宝图上可能地点的数量($1 \le n \le 10^5, 1 \le m \le 10^5$)。

接下来的 $n$ 行输入每行包含 2 个整数。对于 $1 \le j \le n$,第 $j$ 行包含两个整数 $m_1, m_2$($-m \le m_1, m_2 \le m$ 且 $m_1, m_2 \neq 0$),表示第 $j$ 张地图标记的两个地点。

输出格式

如果可能使每张地图都是合理的,输出 YES。否则,输出 NO

样例

输入样例 1

4 2
1 2
2 -1
1 -2
-1 -2

输出样例 1

NO

输入样例 2

3 2
1 2
2 -1
-1 -2

输出样例 2

YES

说明

在样例输入 1 中,不存在任何将地点分配为宝藏或陷阱的方案能使所有地图都合理。例如,如果我们设地点 1 和 2 都包含宝藏,那么地图 4 将不合理;而如果我们设地点 1 包含陷阱且地点 2 包含宝藏,那么地图 3 将不合理。其他情况类似。

在样例输入 2 中,如果地点 1 包含陷阱且地点 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.