P8896 "DPOI-1" Road Planning

Background

No, Commander-in-Chief.

Description

There are $n$ outposts on the battlefield, numbered from $1$ to $n$. There is a bidirectional road between **every pair of outposts**. One day, the Commander-in-Chief came to inspect the war zone. After walking for a while, he got lost, so he angrily gave an order: you must change every bidirectional road into a one-way road, such that these roads **contain no cycles** (otherwise the Commander-in-Chief will get lost). However, since the outposts have different sizes, for outpost $i$, the number of outposts that the Commander-in-Chief can **directly reach** by following one-way roads must be within $[l_i, r_i]$. In other words, the outdegree of node $i$ must be within $[l_i, r_i]$. You need to tell the Commander-in-Chief whether it is possible to satisfy his requirements.

Input Format

**This problem has multiple test cases.** The first line contains an integer $T$, representing the number of test cases. For each test case: The first line contains an integer $n$, representing the number of outposts. The second line contains $n$ integers $l_1, l_2, \dots, l_n$. The third line contains $n$ integers $r_1, r_2, \dots, r_n$.

Output Format

For each test case: Output one line with a string. If the Commander-in-Chief's requirements can be satisfied, output `YES`; otherwise, output `NO`.

Explanation/Hint

#### Explanation for Sample #1 Below is one feasible solution for the first test case: ![](https://cdn.luogu.com.cn/upload/image_hosting/2uvwlydw.png) #### Explanation for Sample #2 This sample satisfies the constraints of test points $3 \sim 6$. #### Constraints **The scores of the test points are not equally distributed.** | Test Point ID | $n \le$ | Special Condition | Score for Each Test Point | | :----------: | :-----------: | :------: | :----: | | $1\sim 2$ | $10$ | None | $5$ | | $3\sim 6$ | $1000$ | None | $5$ | | $7\sim 8$ | $10^5$ | All $l_i = i-1$ or all $l_i \geq \min (i, n - 1)$ | $5$ | | $9 \sim 10$ | $10^5$ | $l_i=0$ or $r_i=n-1$ | $5$ | | $11 \sim 15$ | $10^5$ | None | $10$ | For $100\%$ of the testdata, $1 \leq n \leq 10^5$, $0 \leq l_i \leq r_i < n$, and $1 \leq T \leq 10$. Translated by ChatGPT 5