ГлавнаяСборникиТурнирыРазделыФорумыУчастникиПечатьПомощьО системе

Разделы > Неотсортированные > задача:


Colored hills

Задачи раздела

• Santa Gifts
• Best Grass
• Chessboard Pattern
• Binary transformations
• Bookshelf
• Coin Game
• Cow PinBall
• Cow Sorting
• Colored hills
• Word power
• Word Statistics
• Brackets
• Triangle
• Butterfly
• Galls village
• Sequence
• Bishops

Обратная связь

Если у вас есть предложения или пожелания по работе Contester, посетите форум сайта www.contester.ru.

Лимит времени 1000/1000/4000/4000 мс. Лимит памяти 65000/65000/65000/65000 Кб.

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