406831: GYM102566 H Pussycat
Description
This year the Christmas tree will look like a DAG (Directed Acyclic Graph) with $$$n$$$ nodes and $$$m$$$ edges. Each node will contain a festive candy which has an expiration date. Miaunel wants to eat exactly one candy per day until there is no candy left. To eat a candy he has to first consume all the candies in the subtree of the node the candy is in, or else the Christmas tree would become unbalanced. Knowing how many days each candy has left until expiration, find out if there is a way for Miaunel to eat all the candies and not get sick (by not consuming an expired candy). Output "YES" if there exists an order of eating the candies given the above constraints, or "NO" otherwise.
InputThe first line of the input will contain the number of test cases $$$T$$$ ($$$1 \leq T \leq 10^5$$$).
The first line of each test case will contain the number of nodes $$$n$$$ ($$$1 \leq n \leq 10^5$$$) and the number of edges $$$m$$$ ($$$1 \leq m \leq 10^5$$$)
The second line of each test case will contain $$$e_1, e_2..., e_n$$$ ($$$0 \leq e_i \leq 2^{30}$$$), the number of days left until expiration for each one of the $$$n$$$ candies. The following $$$m$$$ lines will each contain a pair of integers ($$$a, b$$$) signifying that there is an edge from node $$$a$$$ to node $$$b$$$ ($$$1 \leq a, b \leq n$$$).
It is guaranteed that the sum of all $$$n$$$ is less than $$$10^5$$$ and the sum of all $$$m$$$ is less than $$$10^5$$$.
OutputThe output should contain $$$T$$$ lines, each containing an answer to a test.
ExampleInput4 7 6 7 5 6 2 1 4 3 1 2 1 3 2 4 2 5 3 6 3 7 3 2 3 1 1 1 2 1 3 4 4 4 2 3 1 1 2 1 3 2 4 3 4 4 4 4 2 2 1 1 2 1 3 2 4 3 4Output
YES NO YES NO