#C398. Exact Path in Graph

    ID: 47466 Type: Default 1000ms 256MiB

Exact Path in Graph

Exact Path in Graph

This problem asks you to determine whether there exists a path between two nodes in an undirected graph that passes through exactly \(k\) nodes. Formally, you are given a graph with \(n\) vertices and \(m\) edges. Then, you will be given \(q\) queries. Each query is described by three integers \(u\), \(v\), and \(k\), where \(u\) is the starting node, \(v\) is the ending node, and \(k\) is the exact number of nodes (including the starting and ending nodes) that must appear in the path.

Note that the graph is undirected and may contain cycles. A valid path may revisit nodes as long as the total count of nodes in the path is exactly \(k\).

Example:

Input:
6 7
1 2
2 3
3 4
4 5
5 6
1 6
3 6
3
1 4 4
1 6 2
2 5 3

Output: Yes Yes No

</p>

inputFormat

The first line contains two integers \(n\) and \(m\), representing the number of nodes and edges in the graph. The following \(m\) lines each contain two integers \(u\) and \(v\) indicating an undirected edge between nodes \(u\) and \(v\). After that, a line with the integer \(q\) indicates the number of queries. Each of the following \(q\) lines contains three integers \(u\), \(v\), and \(k\), representing a query asking if there exists a path from node \(u\) to node \(v\) that passes through exactly \(k\) nodes.

outputFormat

For each query, output a single line containing either "Yes" or "No" to indicate whether such a path exists.

## sample
6 7
1 2
2 3
3 4
4 5
5 6
1 6
3 6
3
1 4 4
1 6 2
2 5 3
Yes

Yes No

</p>