QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#17183. 图上游戏

統計

给定一个 $n$ 个点 $m$ 条边的联通无向图, 所有节点用 $1\sim n$ 的整数编号. 初始时, 每个节点 $u$ 都有一个权值 $a_u$. 你可以执行如下操作任意多次:

  • 选择两个节点 $u, v$, 满足 $u, v$ 之间有一条边相连, 赋值 $a_u= \min(a_u, a_v)$.

给定 $b_1, \ldots, b_n$, 判断是否可以通过若干次操作将 $a$ 转换为 $b$. 若可以, 输出 Yes, 否则输出 No.

共 $T$ 组数据.

输入格式

第一行,一个整数 $T$ 表示数据组数。

对每组数据, 第一行两个整数 $n, m$.

第二行 $n$ 个整数, 分别是 $a_1, \ldots, a_n$.

第三行 $n$ 个整数, 分别是 $b_1, \ldots, b_n$.

接下来 $m$ 行, 每行两个整数 $u, v$, 表示存在一条连接 $u, v$ 的边.

输出格式

$T$ 行, 每行一个 YesNo, 表示第 $i$ 组数据的答案.

样例

样例输入 1

2
4 4
3 3 2 1
2 1 2 1
1 2
2 3
3 4
4 2
4 4
3 3 2 1
1 2 2 1
1 2
2 3
3 4
4 2

样例输出 1

Yes
No

数据范围

对于 $100\%$ 的数据,$1\le n\le 1.5\times 10^5$,$1\le m\le 2\times 10^5$,$\sum n\times m \le 5\times 10^6$.

$\text{Subtask 1}(20\%)$: 保证有一个点和其他所有点都有连边, 且 $m = n-1$。

$\text{Subtask 2}(40\%)$: 保证图是一棵树。

$\text{Subtask 3}(40\%)$: 无特殊限制。

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.