#P8896. 「DPOI-1」道路规划

    ID: 9924 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>贪心2022洛谷原创O2优化优先队列构造

「DPOI-1」道路规划

Background

No, Commander-in-Chief.

Problem Description

There are nn outposts on the battlefield, numbered from 11 to nn. 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 ii, the number of outposts that the Commander-in-Chief can directly reach by following one-way roads must be within [li,ri][l_i, r_i]. In other words, the outdegree of node ii must be within [li,ri][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 TT, representing the number of test cases.

For each test case:

The first line contains an integer nn, representing the number of outposts.

The second line contains nn integers l1,l2,,lnl_1, l_2, \dots, l_n.

The third line contains nn integers r1,r2,,rnr_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.

2
5
0 1 4 0 0
3 4 4 1 3
3
1 2 2
2 2 2
YES
NO
见下发文件 road2.in
见下发文件 road2.out

Hint

Explanation for Sample #1

Below is one feasible solution for the first test case:

Explanation for Sample #2

This sample satisfies the constraints of test points 363 \sim 6.

Constraints

The scores of the test points are not equally distributed.

Test Point ID nn \le Special Condition Score for Each Test Point
121\sim 2 1010 None 55
363\sim 6 10001000
787\sim 8 10510^5 All li=i1l_i = i-1 or all limin(i,n1)l_i \geq \min (i, n - 1)
9109 \sim 10 li=0l_i=0 or ri=n1r_i=n-1
111511 \sim 15 None 1010

For 100%100\% of the testdata, 1n1051 \leq n \leq 10^5, 0liri<n0 \leq l_i \leq r_i < n, and 1T101 \leq T \leq 10.

Translated by ChatGPT 5