Under construction

Still being built. Things may change

Ordinary graph and strange queries

Time limit2sMemory limit1024 MB

Summary
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 w_iw\_i.

You are given an ordinary undirected weighted graph GG with NN vertices and MM edges. Vertices are numbered from 1 to NN, and each edge weight is a positive integer. You are given QQ queries of the following form.

  • a b k: Consider paths that start at vertex aa and end at vertex bb. If one of them has a length that is a multiple of kk, print Yes. Otherwise, print No.

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 NN, the number of edges MM, and the number of queries QQ, separated by spaces. (2≤N≤100 000;0≤M≤200 000;1≤Q≤100 0002\le N\le 100\ 000; 0\leq M\leq 200\, 000; 1 \leq Q \leq 100\ 000)

Each of the next MM lines contains three integers u_i,v_i,w_iu\_i, v\_i, w\_i, separated by spaces. This means that the ii-th edge connects u_iu\_i and v_iv\_i and has weight w_iw\_i. It is guaranteed that at most one edge connects any pair of vertices. (1≤u_i,v_i≤N;u_i≠v_i;1≤w_i≤1091\leq u\_i,v\_i\leq N; u\_i\neq v\_i; 1\leq w\_i\leq 10^9)

Each of the next QQ lines contains one query in the form a b k. (1≤a,b≤N;a≠b;1≤k≤1091\leq a,b\leq N; a\neq b; 1\leq k\leq 10^9)

All given numbers are integers.

Output

For each query, print Yes if there is a path from vertex aa to vertex bb whose length is a multiple of kk. Otherwise, print No. Print one answer per line, in the order of the queries.

Examples1

  1. Example 1

    Input
    5 4 4
    1 2 2
    1 3 4
    2 3 5
    4 5 3
    4 5 2
    1 2 3
    2 3 2
    1 4 1
    
    Expected output
    No
    Yes
    Yes
    No