[Solution] Count Seconds Codeforces Solution
Cirno has a DAG (Directed Acyclic Graph) with nodes and edges. The graph has exactly one node that has no out edges. The -th node has an integer on it.
Every second the following happens:
- Let be the set of nodes that have .
- For all , is subtracted from , and then for each node , such that there is an edge from to , is added to .
Find the first moment of time when all become . Since the answer can be very large, output it
modulo .
The first line contains a single integer () — the number of test cases. Description of test cases follows.
The first line of each test case contains two integers () — the number of vertices and edges in the graph.
The second line of each test case contains integers () — the integer on vertices.
Each line of the following lines contains two integers (), represent a directed edge from to . It is guaranteed that the graph is a DAG with no multi-edges, and there is exactly one node that has no out edges.
It is guaranteed that both sum of and sum of over all test cases are less than or equal to .
For each test case, print an integer in a separate line — the first moment of time when all become , modulo .
No comments:
Post a Comment