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

#FW0000122. Truy vấn khả năng đi tới (Reachability Queries)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Truy vấn khả năng đi tới (Reachability Queries)

Reachability Queries

Source: CSES

Version: Phuoc Hung OJ Extended

Problem Statement

Given a directed graph with nn nodes and mm edges, possibly containing cycles, answer qq reachability queries (a,b)(a,b). For each query determine if there exists a directed walk from aa to bb. Every node reaches itself by a zero-edge walk.

Input

First line n,m,qn,m,q, then mm directed edges u,vu,v, then qq queries a,ba,b. Nodes are 11-indexed.

Output

Print YES or NO for each query, one per line.

Subtasks

  • Subtask 1 (40 points): 1≤n≤101\le n\le 10, 1≤m≤251\le m\le 25, 1≤q≤151\le q\le 15. All input conditions remain in force.

  • Subtask 2 (60 points): 1≤n≤5⋅1041\le n\le 5\cdot10^4, 1≤m,q≤1051\le m,q\le 10^5. All input conditions remain in force.

Examples

Input

4 4 3
1 2
2 3
3 1
4 3
1 3
1 4
4 1

Output

YES
NO
YES

Explanation

Nodes 1,2,3 form one strongly connected component; node 4 reaches that component but the reverse direction is impossible.