#P40018. 2019 ICPC NA Qualifier Contest H - Running Routes

2019 ICPC NA Qualifier Contest H - Running Routes

题目描述

The administrators at Polygonal School want to increase enrollment, but they are unsure if their gym can support having more students. Unlike a normal, boring, rectangular gym, the gym floor at Polygonal is a regular nn-sided polygon! They affectionately refer to the polygon as PP.

The coach has drawn several running paths on the floor of the gym. Each running path is a straight line segment connecting two distinct vertices of PP. During gym class, the coach assigns each student a different running path, and the student then runs back and forth along their assigned path throughout the class period. The coach does not want students to collide, so each student’s path must not intersect any other student’s path. Two paths intersect if they share a common point (including an endpoint).

Given a description of the running paths in PP, compute the maximum number of students that can run in gym class simultaneously.

image.png

Figure 1: Illustrations of the two sample inputs, with possible solutions highlighted in thick red lines. Solid black lines represent running paths that are not assigned to a student, and dashed black lines are used to show the boundary of $P$ in places where no running path exists.

输入格式

The first line contains an integer nn (3n5003 \le n \le 500), the number of vertices in PP. (The vertices are numbered in increasing order around PP.) Then follows nn lines of nn integers each, representing a n×nn \times n symmetric binary matrix which we’ll call MM. The jthj^{\text {th}} integer on the ithi^{\text {th}} line MijM_{ij} is 11 if a running path exists between vertices ii and jj of the polygon, and 00 otherwise. It is guaranteed that for all 1i,jn1 \le i,j \le n, Mij=MjiM_{ij} = M_{ji} and Mii=0M_{ii}=0.

输出格式

Print the maximum number of students that can be assigned to run simultaneously on the running paths, given the above constraints.

样例

样例输入 1

3
0 1 1
1 0 1
1 1 0

样例输出 1

1

样例输入 2

6
0 0 0 1 0 0
0 0 0 0 1 1
0 0 0 0 1 1
1 0 0 0 0 0
0 1 1 0 0 0
0 1 1 0 0 0

样例输出 2

2