I can solve problem 9999
Time limit1sMemory limit128 MB
Choose yes or no votes for everyone to minimize disagreeing friendships plus votes cast against personal belief.
- Level
Medium7 of 10
- Topics
- Graph
- Solved
- No attempts yet
Problem
People are voting on whether Minhyuk can solve problem 9999. Most of them vote the way they actually think, but some vote against their own belief to avoid disagreeing with a friend.
You are given what each person believes about Minhyuk and problem 9999, together with the friendships among them.
Once the vote is over, add two numbers. The first is the number of friendships whose two members voted differently, and the second is the number of people who voted against their own belief. Write a program that finds the smallest value this sum can take.
Input
The input consists of several test cases.
The first line of each test case has the number of people and the number of friendships . (, )
The second line has numbers describing what each person believes, given in order starting from person 1. A 1 is a person who believes Minhyuk can solve problem 9999, and a 0 is a person who believes he cannot.
Each of the next lines has the numbers of two people who are friends. People are numbered from 1 to .
The last line of the input is , and that line is not a test case.
Output
For each test case, print on one line the minimum value of the number of friendships whose two members voted differently plus the number of people who voted against their own belief.
Hint
In the first test case of the example, only person 1 has to vote against their own belief. In the second test case, everyone votes the way they think.