## Music Fest

View as PDF

Points: 7
Time limit: 2.0s
Memory limit: 256M

Authors:
Problem type

Ms. Holland has been pestering her students for their permission forms for MusicFest for a while now. Every rehearsal, she reminds the students, but it seems either nobody has been paying attention, or nobody cares enough to actually fill it out. Ms. Holland has had enough.

After some digging, Ms. Holland discovers that of the students only attend morning band rehearsals because their friends are there. Of these students, she also learns that the -th student will only fill out the permission form if the -th student (whom the student looks up to) has filled out the form. With this information in hand, Ms. Holland realizes she only needs to pester a few of the students to fill out the form, and others will follow suit.

Ms. Holland wonders what the minimum number of students she must pester is, such that in the end, the entire band has filled the form.

Each is distinct

#### Input Specification

The first line will contain integers and .

The next line will contain space-separated integers, either s or s, indicating if the student has signed their permission form or not. indicates that they have, and indicates they have not.

The next lines will contain two integers, and , indicating that student looks up to student .

Note: The input is not propagated - i.e. there is a possibility that will have a value of while has a value of . Student will still sign the form even though it is not initially specified.

#### Output Specification

Output one integer, the minimum number of students Ms. Holland must pester.

#### Sample Input

15 12
0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
1 2
2 3
3 4
4 2
5 1
6 1
7 6
8 9
9 10
10 11
12 13
14 15

#### Sample Output

3

#### Sample Explanation

If Ms. Holland pesters student 4, 11, and 15, all of the other students will eventually fill out their permission forms.

## Comments

There are no comments at the moment.