#P9565. [SDCPC 2023] Not Another Path Query Problem

[SDCPC 2023] Not Another Path Query Problem

题目背景

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

题目描述

After reading the paper Distributed Exact Shortest Paths in Sublinear Time, you have learned how to solve the distributed single-source shortest paths problem in O(D1/3(nlogn)2/3)\mathcal{O}(D^{1/3} \cdot (n \log n)^{2/3}). To give your knowledge good practice, Little Cyan Fish prepared the following practice task for you.

Little Cyan Fish has a graph consisting of nn vertices and mm bidirectional edges. The vertices are numbered from 11 to nn. The ii-th edge connects vertex uiu_i to vertex viv_i and is assigned a weight wiw_i.

For any path in the graph between two vertices uu and vv, let's define the value of the path as the bitwise AND of the weights of all the edges in the path.

As a fan of high-value paths, Little Cyan Fish has set a constant threshold VV. Little Cyan Fish loves a path if and only if its value is at least VV.

Little Cyan Fish will now ask you qq queries, where the ii-th query can be represented as a pair of integers (ui,vi)(u_i, v_i). For each query, your task is to determine if there exists a path from vertex uiu_i to vertex viv_i that Little Cyan Fish would love it.

输入格式

There is only one test case in each test file.

The first line contains four integers nn, mm, qq and VV (1n1051 \le n \le 10^5, 0m5×1050 \le m \le 5 \times 10^5, 1q5×1051 \leq q \leq 5 \times 10^5, 0V<2600 \leq V < 2^{60}) indicating the number of vertices, the number of edges, the number of queries and the constant threshold.

For the following mm lines, the ii-th line contains three integers uiu_i, viv_i and wiw_i (1ui,vin1 \le u_i,v_i \le n, uiviu_i \ne v_i, 0wi<2600 \leq w_i < 2^{60}), indicating a bidirectional edge between vertex uiu_i and vertex viv_i with the weight wiw_i. There might be multiple edges connecting the same pair of vertices.

For the following qq lines, the ii-th line contains two integers uiu_i and viv_i (1ui,vin1 \leq u_i, v_i \leq n, uiviu_i \ne v_i), indicating a query.

输出格式

For each query output one line. If there exists a path whose value is at least VV between vertex uiu_i and viv_i output Yes, otherwise output No.

9 8 4 5
1 2 8
1 3 7
2 4 1
3 4 14
2 5 9
4 5 7
5 6 6
3 7 15
1 6
2 7
7 6
1 8

Yes
No
Yes
No

3 4 1 4
1 2 3
1 2 5
2 3 2
2 3 6
1 3

Yes

提示

We now use &\& to represent the bitwise AND operation.

The first sample test case is shown as follows.

  • For the first query, a valid path is 134561 \to 3 \to 4 \to 5 \to 6, whose value is 7&14&7&6=657 \,\&\, 14 \,\&\, 7 \,\&\, 6 = 6 \ge 5.
  • For the third query, a valid path is 734567 \to 3 \to 4 \to 5 \to 6, whose value is 15&14&7&6=6515 \,\&\, 14 \,\&\, 7 \,\&\, 6 = 6 \ge 5.
  • For the fourth query, as there is no path between vertex 11 and 88, the answer is No.

For the only query of the second sample test case, we can consider the path consisting of the 22-nd and the 44-th edge. Its value is 5&6=445 \,\&\, 6 = 4 \ge 4.