#P3247. [HNOI2016] 最小公倍数
[HNOI2016] 最小公倍数
Description
Given an undirected graph with vertices and edges (the vertices are numbered ). Each edge has a weight, and every weight can be factorized as .
There are queries. In each query, you are given four parameters , and . Please determine whether there exists a path from vertex to vertex such that the least common multiple of the weights of the edges traversed along the path is exactly .
Note: The path does not have to be simple.
Below are some definitions that may be useful. If they differ from other sources, use the definitions below for this problem:
Least common multiple: The least common multiple of numbers is the smallest positive integer that is divisible by each .
Path: A vertex sequence is a path if and only if , and for any , there is an edge between and .
Simple path: If in a path , it holds that for any , then is called a simple path.
Input Format
The first line contains two integers and , the number of vertices and edges of the graph.
Each of the next lines contains four integers , representing an edge between vertices and with weight .
The next line contains an integer , the number of queries.
Each of the next lines contains four integers , and , representing one query. See the problem description for details.
Output Format
For each query, output one line: Yes if such a path exists, otherwise output No (note: the first letter is uppercase, the rest are lowercase).
4 5
1 2 1 3
1 3 1 2
1 4 2 1
2 4 3 2
3 4 2 2
5
1 4 3 3
4 2 2 3
1 3 2 2
2 3 2 2
1 3 4 4
Yes
Yes
Yes
No
No
Hint
Constraints: , , .
Translated by ChatGPT 5
京公网安备 11011102002149号