#agc039b. [agc039_b]Graph Partition
[agc039_b]Graph Partition
Problem Statement
Given is a connected undirected graph with vertices and edges. The vertices are numbered to , and the edges are described by a grid of characters . If is 1
, there is an edge connecting Vertex and ; otherwise, there is no such edge.
Determine whether it is possible to divide the vertices into non-empty sets such that the following condition is satisfied. If the answer is yes, find the maximum possible number of sets, , in such a division.
- Every edge connects two vertices belonging to two "adjacent" sets. More formally, for every edge , there exists such that or holds.
Constraints
- is
0
or1
. - is
0
. - The given graph is connected.
- is an integer.
Input
Input is given from Standard Input in the following format:
Output
If it is impossible to divide the vertices into sets so that the condition is satisfied, print . Otherwise, print the maximum possible number of sets, , in a division that satisfies the condition.
Sample Input 1
2
01
10
Sample Output 1
2
We can put Vertex in and Vertex in .
Sample Input 2
3
011
101
110
Sample Output 2
-1
Sample Input 3
6
010110
101001
010100
101000
100000
010000
Sample Output 3
4