| Problem ID | 1094 |
|---|---|
| Title | Perfect Plan |
| Description | There are many students in the CSE department. Some of them are friends, some of them are not. We have a rule of friendship: if ABC are 3 students, AB, BC are friends will imply that AC are also friends, i.e. friend’s friend is also friend. Maintaining friendship is not easy, so every student will have a number in his mind, which indicates the best value of the amount of his friends. If the amount of his friends is more or less than this best value, he is unhappy. Our target is to give a perfect friend-making plan so that all students are happy. Don’t worry! You are not required to make this plan. What you need to do is only to write a program to verify whether the given plan is a perfect plan which will make all students happy. |
| Input | The first line contains an integer T (1 ≤ T ≤ 10), the number of test case. Each of the test case starts with 2 integers N (1 ≤ N ≤ 1000) and M (1 ≤ M ≤ 1000). N is the number of students, and M is the number of friendships in the given plan. The next line will contain N non-negative integers v0 , v1 , v2 ...vn−1 and vi is the best amount of friends for the i-th student. The following M lines describe the plan you need to verify. Each line contains a pair of integers a and b, representing that the a-th student and b-th student are friends in this plan. |
| Output | The output will consist of T lines. If the plan is perfect, output ‘YES’. Otherwise, output ‘NO’. |
| Sample Input | 2 4 2 2 3 2 0 0 1 1 2 4 2 2 2 2 0 0 1 1 2 |
| Sample Output | NO YES |
| Hint | There are 2 test cases in the sample input. For the first test case, student 0 and student 1 are friends, student 1 and student 2 are friends (student 0 and student 2 are also friends based on our rule of friendship). So the plan in 1st test case is not a perfect plan because student 1 is unhappy, thus we print ‘NO’ in the first line. In the second test case, the best number of friends in the mind of student 1 is two, which equals his actual number of friends, so he is also happy in test case 2. As all students are happy in this test case, we print ‘YES’ in the second line. |
| Last Modified | 2012-10-11 22:06:14 |
| Time Limit | 1 seconds |
| Memory Limit | 64 MB |
| Accepted Solutions | 1 |
| Submitted Solutions | 3 |
| Difficulty Factor | 286 |
Facebook