Two paths
Practice
4 (2 votes)
Algorithms
Approved
Graphs
Medium
Problem
55% Success 1059 Attempts 50 Points 2s Time Limit 512MB Memory 1024 KB Max Code

Given an undirected graph with n vertices and m edges. Each edge is one of the two types: white and black.

There are q queries denoted by four vertices a, b, c and d. Each query asks: can some of the black edges be deleted, so that a is reachable from b, but c is not reachable from d? Note that graph itself doesn't change from query to query.

Input format

The first line contains three integers n, m and q (\(1 \leq n, m, q \leq 2 \cdot 10^5\)) - number of vertices, number of edges and number of queries, respectively.

Then m lines follow.

The i-th of them contains three integers \(a_i\), \(b_i\) and \(t_i\) (\(1 \leq a_i, b_i \leq n\), \(a_i \neq b_i\), \(t_i \in {0, 1}\)) describing edge connecting \(a_i\) and \(b_i\), \(t_i = 0\) for black edge and \(t_i = 1\) for white edge.

Then q lines follow.

The i-th of them contains four integers \(a_i\), \(b_i\), \(c_i\) and \(d_i\) (\(1 \leq a_i, b_i, c_i, d_i \leq n\) — vertices in the i-th query.

Output format

For each query print Yes if it's possible to delete some black edges and satisfy the condition. Print No otherwise.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
13 votes
Tags:
Data StructuresGraphsMediumTrees
Points:50
23 votes
Tags:
AlgorithmsArticulation Points and BridgesBridgesC++Graphs