Under construction

Still being built. Things may change

Werewolf

Time limit4sMemory limit537 MB

Summary
For each trip, decide whether a route from S to E exists that switches form at a city in [L, R], staying at or above L before the switch and at or below R after it.
Level

Hard8 of 10

Topics
Graph, Union-find, Segment tree
Solved
No attempts yet

Problem

There are NN cities and MM roads in Ibaraki Prefecture, Japan. Cities are numbered from 0 through N−1N-1 in increasing order of their population. Each road connects a pair of distinct cities and can be traveled in both directions. You can travel from any city to any other city by using one or more of these roads.

You have planned QQ trips, numbered from 0 through Q−1Q-1. Trip ii (0≤i≤Q−10 ≤ i ≤ Q-1) travels from city SiS_i to city EiE_i.

You are a werewolf. You have two forms: human form and wolf form. At the beginning of each trip you are in human form. At the end of each trip you must be in wolf form. During a trip you have to transform (change from human form to wolf form) exactly once. You can transform only when you are in a city, and that city may be SiS_i or EiE_i.

You must avoid low-populated cities when you are in human form, and avoid highly-populated cities when you are in wolf form. For each trip ii, two thresholds LiL_i and RiR_i (0≤Li≤Ri≤N−10 ≤ L_i ≤ R_i ≤ N-1) decide which cities to avoid. In human form you must avoid cities 0,1,...,Li−10, 1, ..., L_i-1. In wolf form you must avoid cities Ri+1,Ri+2,...,N−1R_i+1, R_i+2, ..., N-1. So in trip ii, you can transform only in one of the cities Li,Li+1,...,RiL_i, L_i+1, ..., R_i.

For each trip, determine whether it is possible to travel from SiS_i to EiE_i while satisfying these constraints. The route can have any length.

Constraints

2 ≤ NN ≤ 200,000. N−1N-1 ≤ MM ≤ 400,000. 1 ≤ QQ ≤ 200,000. For each jj (0≤j≤M−10 ≤ j ≤ M-1): 0 ≤ XjX_j ≤ N−1N-1, 0 ≤ YjY_j ≤ N−1N-1, and Xj≠YjX_j ≠ Y_j. Any city can reach any other city by using roads. Each pair of cities is directly connected by at most one road. For each ii (0≤i≤Q−10 ≤ i ≤ Q-1): 0 ≤ LiL_i ≤ SiS_i ≤ N−1N-1, 0 ≤ EiE_i ≤ RiR_i ≤ N−1N-1, Si≠EiS_i ≠ E_i, and Li≤RiL_i ≤ R_i.

Examples1

  1. Example 1

    Input
    2 1
    0 1
    1
    0 1 0 1
    
    Expected output
    YES