HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Contests > Bil-273 Uchunchu praktika 02.10.2019 > problem:


4. Colored hills

Bil-273 Uchunchu praktika 02.10.2019

Start: Oct.02.2019 at 02:00:00 PM
Finish: Oct.02.2019 at 05:00:00 PM
The contest is finished!
• Contest scoreboard

Contest problems

• 1. Big Dance
• 2. Bookshelf
• 3. Coin Game
• 4. Colored hills

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 1000/1000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb.

Problem description

There are N colored hills. Some of them are connected with bridges. We want to paint bridges to the same color with the hills they connect. But it is not always possible (when connected hills have different colors). Calculate number of bridges that can not be painted.

Input

There is a single integer on the first line of input N (1 <= N <= 100), then N lines with N integers (0 - no brige, 1 - connected with bridge, adjacency matrix of graph). In the last line there are N integers from 1 to 3 - colors of hills.

Output

Write number of bridges that can not be painted.

Example

stdin stdout

7
0 1 0 0 0 1 1
1 0 1 0 0 0 0
0 1 0 0 1 1 0
0 0 0 0 0 0 0
0 0 1 0 0 1 0
1 0 1 0 1 0 0
1 0 0 0 0 0 0
1 1 1 1 1 3 3

4

Для отправки решений необходимо выполнить вход.

www.contester.ru