14761476 SUSTech Online Judge
Problem 1476 --Catch Spy

1476: Catch Spy

Time Limit: 1 Sec  Memory Limit: 1024 MB
Submit: 103  Solved: 29
[Submit][Status][Web Board]

Description

There are n spies(number of 1~n), some spies know who is spy. There are j spies can be caught, each cost \(w_i\). Once these spy are caught, they will tell out all the spies he know. If all the spies can be caught, please output the minimum cost, otherwise, please output the minimum No. of the spies which cannot be caught.

Input

The first line contains an integer n \((1\leq n \leq 100000)\), indicating there are n spies in total.

The second line contains an integer j \((1\leq j \leq n)\), indicating there are j spies can be caught directly.

The next j lines, each line contains two integers b, w \((1\leq b \leq n, 1\leq w \leq 1000)\), indicating catch spy_b directly need cost w.

The next line contains an integer k \((1\leq k \leq 100000)\),

The next k lines, each line contains two integer u, v, \((1\leq u, v \leq n)\), indicating spy_u knows the information of spy_v. 

Output

If all the spies can be caught, please output YES in the first line and output the minimum cost in the second line.

If not all the spies can be caught, please output NO in the first line and output the minimum No. in the second line.

Sample Input

3
2
1 10
2 100
2
1 3
2 3

Sample Output

YES
110

HINT

Source

 

[Submit][Status]