PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FW0000123. Truy vấn hành trình đúng số bước (Fixed Length Walk Queries)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Truy vấn hành trình đúng số bước (Fixed Length Walk Queries)

Fixed Length Walk Queries

Source: CSES

Version: Phuoc Hung OJ Extended

Problem Statement

Given a connected, simple, undirected graph with at least two nodes, each turn traverses one edge. For every query (a,b,x)(a,b,x) determine if a walk starting at aa can end at bb after exactly xx edge traversals. Revisiting edges or nodes is allowed. Parity matters.

Input

First line n,m,qn,m,q, then mm undirected edges u,vu,v, and qq lines a,b,xa,b,x. Nodes are 11-indexed.

Output

Print YES or NO per query.

Subtasks

  • Subtask 1 (40 points): 2≤n≤122\le n\le 12, n−1≤m≤22n-1\le m\le 22, 1≤q≤151\le q\le 15, 0≤x≤200\le x\le 20. All input conditions remain in force.

  • Subtask 2 (60 points): 2≤n≤25002\le n\le 2500, n−1≤m≤5000n-1\le m\le 5000, 1≤q≤1051\le q\le 10^5, 0≤x≤1090\le x\le 10^9. All input conditions remain in force.

Examples

Input

4 5 6
1 2
2 3
1 3
2 4
3 4
1 2 2
1 4 1
1 4 5
2 2 1
2 2 2
3 4 8

Output

YES
NO
YES
NO
YES
YES

Explanation

The first query has walk 1->3->2 of length 2; there is no one-step edge 1->4; round trips add two steps.