Mock CCO '17 Problem 4 - Guards

View as PDF

Submit solution

Points: 15 (partial)
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type

imaxblue has sneaked into an Amestris military base and is waiting for Fuhrer King Bradley's arrival. But first, he must take care of the N guards. There are two types of guards, ones with bulletproof armour and ones with fireproof armour. imaxblue has two weapons, Molotov cocktails and shotguns. Unfortunately, M pairs of guards are one-way friends with each other, therefore imaxblue must kill some guards before others. He would like to know the minimum number of times he needs to change weapons while following the order of friendships.

Input Specification

Line 1: N and M (N,M200000)
Line 2: N integers, either 0 or 1, representing the type of each guard
Lines 3M+2: 2 integers ai and bi, representing that ai must be killed before bi
It is guaranteed that it will be possible to kill all guards. There may be multiple connections between the same pair.

Output Specification

Print on the first line the minimum number of times imaxblue is required to change his weapon.

Sample Input

Copy
6 4
0 1 0 1 1 1
0 1
3 2
1 2
2 5

Sample Output

Copy
3

Comments

There are no comments at the moment.