Hunting Sleeping Pills

4

1 votes
Problem

Now Mr. MAZ is running short on sleeping pills, so he is searching them from planets to planets.
Finally he reaches the planet where he finds them.
There are many countries and in each country there may be one or more cities and a country can be a part of another country. Each city has 0 (zero) or more sleeping pills. Cities are connected by unidirectional paths.
A country is defined as a group of well connected cities such that if we start from any city of that country we can come back to that same city following the unidirectional paths.
Mr. MAZ is allowed to visit only one country. You being his favorite student, he asked you to help him select the country that has maximum number of pills.

Input:
First line of test file contains T, denoting number of test cases.
Next line of each test case contain two space separated integers N and M. N - number of cities and M - number of paths.
Next line contain N space separated integers denoting the number of pills in ith city. Next M lines each contains two space separated integers A and B denoting path from A to B.

Output:
For each test case output single integer containing maximum number of pills that he can collect by visiting only one country.

Constraints:
1T100
1N100
0Number of pills in cities1000
0MN(N-1)
0* ≤ A,B < N

No Partial Marking for this question

Problem Setter: Prashant Arya

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?