koishi_offical @ 2021-01-13 13:56:16
#include<bits/stdc++.h>
using namespace std;
const int inf=1<<29,N=4e6;
int n,m,s=0,t,h[N],e[N],ne[N],w[N],d[N],idx,now[N];
void add(int a,int b,int c)
{
e[idx]=b;
ne[idx]=h[a];
h[a]=idx;
w[idx++]=c;
e[idx]=a;
ne[idx]=h[b];
h[b]=idx;
w[idx++]=0;
}
bool bfs() {
queue<int> q;
q.push(s);
memset(d,0,sizeof(d));
d[s]=1;
now[s]=h[s];
while(!q.empty())
{
int x=q.front();
q.pop();
for(int i=h[x];i!=-1;i=ne[i])
if(w[i]&&!d[e[i]])
{
now[e[i]]=h[e[i]];
q.push(e[i]);
d[e[i]]=d[x]+1;
if(e[i]==t) return 1;
}
}
return 0;
}
int dinic(int x,int flow)
{
if(x==t) return flow;
int rest=flow,k,i;
for(int i=now[x];i!=-1&&rest;i=ne[i])
if(w[i]&&d[e[i]]==d[x]+1)
{
k=dinic(e[i],min(w[i],rest));
if(!k) d[e[i]]=0;
w[i]-=k;
w[i^1]+=k;
rest-=k;
}
now[x]=i;
return flow-rest;
}
int flag[210][210];
int dx[8]={1,1,-1,-1,2,2,-2,-2},dy[8]={2,-2,2,-2,1,-1,1,-1};
int maxflow;
int main () {
int n,m;
memset(h,-1,sizeof(h));
cin>>n>>m;
t=n*n+1;
for(int i=1;i<=m;i++)
{
int x,y;
cin>>x>>y;
flag[x][y]=1;
}
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(!flag[i][j])
{
if((i+j)&1) add(s,(i-1)*n+j,1);
else add((i-1)*n+j,t,1);
}
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if((i+j)&1)
{
for(int k=0;k<8;k++)
if(i+dx[k]>=1&&i+dx[k]<=n&&j+dy[k]>=1&&j+dy[k]<=n&&!flag[i+dx[k]][j+dy[k]])
add((i-1)*n+j,(i+dx[k]-1)*n+j+dy[k],inf);
}
int flow=0;
while(bfs())
while(flow=dinic(s,inf)) maxflow+=flow;
cout<<n*n-m-maxflow;
}
by koishi_offical @ 2021-01-13 13:56:51
码风好丑啊