atcoder#AGC039B. [AGC039B] Graph Partition
[AGC039B] Graph Partition
Score : points
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.
2
01
10
2
We can put Vertex in and Vertex in .
3
011
101
110
-1
6
010110
101001
010100
101000
100000
010000
4