Ordinary graph and strange queries
Time limit2sMemory limit1024 MB
Given a weighted undirected graph, answer for each query whether some walk from a to b has a total length that is a multiple of k.
- Level
Medium7 of 10
- Topics
- DFS, Graph, Number theory
- Solved
- No attempts yet
Problem
This problem is the same as the simple graph and strange queries problem, except for the constraints on .
You are given an ordinary undirected weighted graph with vertices and edges. Vertices are numbered from 1 to , and each edge weight is a positive integer. You are given queries of the following form.
a b k: Consider paths that start at vertex and end at vertex . If one of them has a length that is a multiple of , printYes. Otherwise, printNo.
A path may contain the same vertex or the same edge more than once. The length of a path is the sum of the weights of the edges it contains. If an edge appears several times in a path, its weight is added to the length once for each time the path crosses it. Process the queries correctly.
Input
The first line contains the number of vertices , the number of edges , and the number of queries , separated by spaces. ()
Each of the next lines contains three integers , separated by spaces. This means that the -th edge connects and and has weight . It is guaranteed that at most one edge connects any pair of vertices. ()
Each of the next lines contains one query in the form a b k. ()
All given numbers are integers.
Output
For each query, print Yes if there is a path from vertex to vertex whose length is a multiple of . Otherwise, print No. Print one answer per line, in the order of the queries.