Under construction

Still being built. Things may change

Simple Graph and Strange Queries

Time limit2sMemory limit1024 MB

Summary
Given an unweighted undirected graph, answer for each query whether a walk from a to b has a length that is a multiple of k.
Level

Medium7 of 10

Topics
Graph, BFS, Number theory
Solved
No attempts yet

Problem

A simple undirected weighted graph GG with NN vertices and MM edges is given. Vertices are numbered from 11 to NN, and the weight of every edge is exactly 11. There are QQ queries of the following form.

  • a b k: If there is a path from vertex aa to vertex bb whose length is a multiple of kk, print Yes. Otherwise, print No.

A path may repeat vertices or edges. The length of a path is the sum of the weights of the edges on it, so an edge that appears several times adds its weight once per traversal. Handle the queries correctly.

Input

The first line contains three integers NN, MM, and QQ, separated by spaces. (2≤N≤100 0002\le N\le 100\,000; 0≤M≤200 0000\le M\le 200\,000; 1≤Q≤100 0001\le Q\le 100\,000)

Each of the next MM lines contains three integers uiu_i, viv_i, and wiw_i, meaning that edge ii connects uiu_i and viv_i and has weight wiw_i. Each pair of vertices is connected by at most one edge. (1≤ui,vi≤N1\le u_i,v_i\le N; ui≠viu_i\neq v_i; wi=1w_i=1)

Each of the next QQ lines, starting from line M+2M+2, contains a query in the form a b k. (1≤a,b≤N1\le a,b\le N; a≠ba\neq b; 1≤k≤1091\le k\le 10^9)

All input values are integers.

Output

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

Examples1

  1. Example 1

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