#P8896. 「DPOI-1」道路规划
「DPOI-1」道路规划
Background
No, Commander-in-Chief.
Problem Description
There are outposts on the battlefield, numbered from to . 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 , the number of outposts that the Commander-in-Chief can directly reach by following one-way roads must be within . In other words, the outdegree of node must be within . 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 , representing the number of test cases.
For each test case:
The first line contains an integer , representing the number of outposts.
The second line contains integers .
The third line contains integers .
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 .
Constraints
The scores of the test points are not equally distributed.
| Test Point ID | Special Condition | Score for Each Test Point | |
|---|---|---|---|
| None | |||
| All or all | |||
| or | |||
| None |
For of the testdata, , , and .
Translated by ChatGPT 5