8507: Range Reachability Query

内存限制:128 MB 时间限制:10 S
题面:传统 评测方式:文本比较 上传者:
提交:2 通过:0

题目描述

You are given a directed acyclic graph with n vertices and mm edges. The vertices are labeled by 1,2,,n, and the edges are labeled by 1,2,,m.

You will be given qqueries. In the i-th query, you will be given four integers ui,vili and ri (1lirim). You need to answer whether vertex ui can reach vertex vi when only edges labeled by k (likri) are available.

输入格式

The first line contains a single integer T (1T10), the number of test cases. For each test case:

The first line contains three integers n,m and q (2n50,0001m100,0001q50,000), denoting the number of vertices, the number of edges, and the number of queries.

Each of the following m lines contains two integers ui and vi (1ui<vin), denoting a directed edge from vertex ui to vertex vi.

In the next q lines, the ith line contains four integers uivili and ri (1ui<vin1lirim), describing the i-th query.

输出格式

For each query, print a single line. If vertex ui can reach vertex vi when only edges labeled by k (likri) are available, print ''YES''. Otherwise, print ''NO''.

输入样例 复制

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

输出样例 复制

NO
YES
YES
YES
NO