F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Range Reachability Query

Time Limit: 10000/10000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 630    Accepted Submission(s): 135


Problem Description
You are given a directed acyclic graph with $n$ vertices and $m$ edges. The vertices are labeled by $1,2,\dots,n$, and the edges are labeled by $1,2,\dots,m$.

You will be given $q$ queries. In the $i$-th query, you will be given four integers $u_i$, $v_i$, $l_i$ and $r_i$ ($1\leq l_i\leq r_i\leq m$). You need to answer whether vertex $u_i$ can reach vertex $v_i$ when only edges labeled by $k$ ($l_i\leq k\leq r_i$) are available.
 

Input
The first line contains a single integer $T$ ($1 \leq T \leq 10$), the number of test cases. For each test case:

The first line contains three integers $n,m$ and $q$ ($2 \leq n \leq 50\,000$, $1\leq m\leq 100\,000$, $1\leq q\leq 50\,000$), denoting the number of vertices, the number of edges, and the number of queries.

Each of the following $m$ lines contains two integers $u_i$ and $v_i$ ($1\leq u_i < v_i\leq n$), denoting a directed edge from vertex $u_i$ to vertex $v_i$.

In the next $q$ lines, the $i$-th line contains four integers $u_i$, $v_i$, $l_i$ and $r_i$ ($1\leq u_i < v_i\leq n$, $1\leq l_i\leq r_i\leq m$), describing the $i$-th query.
 

Output
For each query, print a single line. If vertex $u_i$ can reach vertex $v_i$ when only edges labeled by $k$ ($l_i\leq k\leq r_i$) are available, print ''$\texttt{YES}$''. Otherwise, print ''$\texttt{NO}$''.
 

Sample Input
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
 

Sample Output
NO YES YES YES NO
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 07:21:41, Gzip enabled