Time limit: 1 second Memory limit: 256 MB The first practical exam of the final of the…
- User
Time limit: 1 second Memory limit: 256 MB The first practical exam of the final of the 32nd Iran Computer Olympiad After watching the movie Madagascar, Alijan fell in love with the character of the zebra and started his own research on this animal species. He recently noticed in one of the national parks, there is a zebra whose body color is very interesting.
Alijan simulated the zebra's body as an undirected and connected graph, each vertex of which is black or white. The zebra has the ability to be like one of its heads v Select v and the color of all the vertices of the matching component is the same color v v be changed. In other words, the top color u u is changed if a path from v v to u There exists u whose vertices are all the same color.
Alijan loves zebras and doesn't like that all vertices related to the zebra's body are the same color. In order to be able to protect the zebra, it needs to find the least possible operation to match all the vertices. Help him find this amount.
To better understand the question, pay attention to the description of the input examples.
input In the first line, enter two natural numbers n n number of vertices and m m number of edges are sorted.
1 ≤ n ≤ 2000 1≤n≤2000 1 ≤ m ≤ 5000 1≤m≤5000
In the second input line c 1 , c 2 , ⋯ c n c 1 c 2 ,⋯c n They come in order. c i c i Related to the color of the head i i is the amount 0 0 represents white color and value 1 1 represents the black vertex. 0 ≤ c i ≤ 1 0≤c i ≤1 in each of m m next row, two ends of each ridge v i v i and u i u i it comes 1 ≤ v i , u i ≤ n 1≤v i ,u i ≤n
output On the only output line, print the fewest possible operations to make the zebra monochrome.
Sub-issues Constraint score subproblem 1 10 n ≤ 20 n≤20 2 10 m
n
1 m=n−1 and for each 1 ≤ i ≤ n
1 1≤i≤n−1 is an edge between vertices i i and i + 1 There are i+1. 3 40 m
n
1 m=n−1 440 without additional restrictions Example Sample entry 1 7 8 1 0 0 1 1 0 1 1 2 1 3 2 4 3 4 4 5 4 6 5 7 6 7 Plain text Sample output 1 2 Plain text Alijan can whiten all graph vertices in two steps by selecting vertices 4 and 1.
Sample input 2 9 8 1 0 1 0 1 0 1 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 Plain text Sample output 2 4 write in java
- Assistant