Werewolf
Time limit4sMemory limit537 MB
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 cities and roads in Ibaraki Prefecture, Japan. Cities are numbered from 0 through 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 trips, numbered from 0 through . Trip () travels from city to city .
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 or .
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 , two thresholds and () decide which cities to avoid. In human form you must avoid cities . In wolf form you must avoid cities . So in trip , you can transform only in one of the cities .
For each trip, determine whether it is possible to travel from to while satisfying these constraints. The route can have any length.
Constraints
2 ≤ ≤ 200,000. ≤ ≤ 400,000. 1 ≤ ≤ 200,000. For each (): 0 ≤ ≤ , 0 ≤ ≤ , and . Any city can reach any other city by using roads. Each pair of cities is directly connected by at most one road. For each (): 0 ≤ ≤ ≤ , 0 ≤ ≤ ≤ , , and .