P9565 [SDCPC 2023] Not Another Path Query Problem

题目背景

> What age is it that you are still solving traditional path query problems?

题目描述

**【题目背景】** > 都什么年代了还在做传统路径查询问题? 在阅读《Distributed Exact Shortest Paths in Sublinear Time》这篇论文后,您学会了如何在 $\mathcal{O}(D^{1/3} \cdot (n \log n)^{2/3})$ 的复杂度内解决分布式单源最短路问题。为了测试您是否真的学有所成,小青鱼为您准备了如下问题。 小青鱼有一张包含 $n$ 个节点与 $m$ 条无向边的图,节点编号从 $1$ 到 $n$。第 $i$ 条边连接节点 $u_i$ 和 $v_i$,边权为 $w_i$。 对于任意一条连接节点 $u$ 和 $v$ 的路径,定义路径的价值为路径上所有边的边权进行按位与(bitwise AND)计算的结果。 小青鱼很喜欢高价值的路径,因此他设定了一个固定的阈值 $V$。称小青鱼喜爱一条路径,当且仅当这条路径的价值至少为 $V$。 接下来,小青鱼将会提出 $q$ 次询问,第 $i$ 次询问可以用一对整数 $(u_i, v_i)$ 表示。对于每次询问,您需要判断节点 $u_i$ 到 $v_i$ 是否存在一条小青鱼喜爱的路径。

输入格式

输出格式

说明/提示

We now use $\&$ to represent the bitwise AND operation. The first sample test case is shown as follows. ![](https://cdn.luogu.com.cn/upload/image_hosting/xdxp1um6.png) - For the first query, a valid path is $1 \to 3 \to 4 \to 5 \to 6$, whose value is $7 \,\&\, 14 \,\&\, 7 \,\&\, 6 = 6 \ge 5$. - For the third query, a valid path is $7 \to 3 \to 4 \to 5 \to 6$, whose value is $15 \,\&\, 14 \,\&\, 7 \,\&\, 6 = 6 \ge 5$. - For the fourth query, as there is no path between vertex $1$ and $8$, the answer is `No`. For the only query of the second sample test case, we can consider the path consisting of the $2$-nd and the $4$-th edge. Its value is $5 \,\&\, 6 = 4 \ge 4$.