luogu#P4899. [IOI 2018] werewolf 狼人

    ID: 3929 远端评测题 4000ms 537MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2018树状数组Kruskal 重构树IOIO2优化深度优先搜索 DFS可持久化线段树

[IOI 2018] werewolf 狼人

Background

This problem is an interactive problem, but here you should submit a full program.

Problem Description

In Ibaraki Prefecture, Japan, there are NN cities and MM roads. The cities are sorted in increasing order of population and are numbered from 00 to N1N - 1. Each road connects two different cities and can be traveled in both directions. Using these roads, you can travel from any city to any other city.

You have planned QQ trips, numbered from 00 to Q1Q - 1. Trip i(0iQ1)i(0 \leq i \leq Q - 1) goes from city SiS_i to city EiE_i.

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

Life as a werewolf is not easy. When you are in human form, you must avoid cities with small populations, and when you are in wolf form, you must avoid cities with large populations. For each trip i(0iQ1)i(0 \leq i \leq Q - 1), there are two thresholds LiL_i and Ri(0LiRiN1)R_i(0 \leq L_i \leq R_i \leq N - 1) that describe which cities must be avoided. More precisely, when you are in human form, you must avoid cities 0,1,,Li10, 1, \ldots , L_i - 1; when you are in wolf form, you must avoid cities Ri+1,Ri+2,,N1R_i + 1, R_i + 2, \ldots , N - 1. This means that in trip ii, you must transform in one of the cities Li,Li+1,,RiL_i, L_i + 1, \ldots , R_i.

Your task is: for each trip, determine whether it is possible to travel from city SiS_i to city EiE_i while satisfying the restrictions above. Your route may have any length.

Input Format

The first line contains three positive integers N,M,QN, M, Q, as described above.

The next MM lines each contain two non-negative integers. In these MM lines, the jj-th line contains Xj1,Yj1X_{j - 1}, Y_{j - 1}, meaning that road number j1j - 1 connects those two cities.

The next QQ lines each contain four non-negative integers. In these QQ lines, the ii-th line contains Si1,Ei1,Li1,Ri1S_{i - 1}, E_{i - 1}, L_{i - 1}, R_{i - 1}, meaning that trip number i1i - 1 starts at city Si1S_{i - 1}, ends at city Ei1E_{i - 1}, and has the two thresholds.

Output Format

Output QQ lines, each containing an integer that is either 00 or 11. The integer on line ii indicates whether, for trip number i1i - 1, it is possible to travel from city Si1S_{i - 1} to city Ei1E_{i - 1}. Output 11 if it is possible, otherwise output 00.

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

1
0
0

10 9 10
6 7
1 5
8 0
2 9
9 4
2 7
8 5
6 0
3 4
4 9 0 9
8 1 8 9
1 8 1 8
8 3 5 5
8 9 3 9
0 1 0 2
9 0 6 6
1 7 1 8
9 4 5 6
9 5 0 9

1
1
1
0
1
1
0
1
0
1

Hint

Constraints

  • 2N200,0002 \leq N \leq 200, 000
  • N1M400,000N - 1 \leq M \leq 400, 000
  • 1Q200,0001 \leq Q \leq 200, 000
  • For each 0jM10 \leq j \leq M - 1
    • 0XjN10 \leq X_j \leq N - 1
    • 0YjN10 \leq Y_j \leq N - 1
    • XjYjX_j \neq Y_j
  • You can travel from any city to any other city using the roads.
  • Each pair of cities is directly connected by at most one road. In other words, for all 0j<kM10 \leq j < k \leq M - 1, (Xj,Yj)(Xk,Yk)(X_j, Y_j) \neq (X_k, Y_k) and (Yj,Xj)(Xk,Yk)(Y_j, X_j) \neq (X_k, Y_k).
  • For each 0iQ10 \leq i \leq Q - 1
    • 0LiSiN10 \leq L_i \leq S_i \leq N - 1
    • 0EiRiN10 \leq E_i \leq R_i \leq N - 1
    • SiEiS_i \neq E_i
    • LiRiL_i \leq R_i

Subtasks

    1. (7 points) N100N \leq 100, M200M \leq 200, Q100Q \leq 100.
    1. (8 points) N3,000N \leq 3, 000, M6,000M \leq 6, 000, Q3,000Q \leq 3, 000.
    1. (34 points) M=N1M = N - 1 and each city is connected to at most two roads (all cities form a single line).
    1. (51 points) No additional constraints.

Translated by ChatGPT 5