Fantastic University BHU

5

3 votes
Easy-Medium
Problem

BHU is a fantastic university, and all its departments are superb indeed. However, some of these departments are rather exclusive.

Overall, BHU consists of exactly N departments enumerated using integers from 1 to N, and M of them are considered to be exclusive (M ≤ N). These departments are connected by R bi-directional roads, where the ith roads connects two distinct departments x and y.

Now, we call the Exclusive Power of departments to be the number of exclusive departments that are reachable from it. We say that department A is reachable from department B, if by starting from department B and traversing some sequence of roads in BHU, we can reach department A.

Your task is to find the summation of the Exclusive Power of all N departments in BHU.

Input Format :

The first line contains 3 space separated integers N, M and R, denoting the number of departments, number of exclusive departments and the number of roads in BHU.

Second line contains M space separated integers, denoting the indexes of the exclusive departments. Next R lines contains 2 space separated integers x and y, denoting bi-directional road between department x and y.

Output Format :

Print a single integer denoting the answer to the problem.

Constraints :

1 ≤ M ≤ N ≤ 105
1 ≤ R ≤ 105
1 ≤ x,y ≤ N
x ≠ y

Sample Input
4 3 2
1 3 4
1 2
2 3
Sample Output
7
Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

Department 1, 2 and 3 have a Exclusive Power equal to 2 where-as department 4 has a Exclusive Power equal to 1.

So, sum of all exclusive powers is - 2 + 2 + 2 + 1 = 7

Editor Image

?