#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int MAXN=40005,MAXM=400005;
const LL INF=1e17,MXD=1e7;
int N,M,S,T,K,et=1;
const int dx[8]={1,1,-1,-1,3,3,-3,-3};
const int dy[8]={3,-3,3,-1,1,-1,1,-1};
struct Edge
{
int to,nxt;
LL fl;
}e[MAXM<<1];
int hd[MAXN],dep[MAXN],cur[MAXN];
void Add(int u,int v,LL fl)
{
e[++et]={v,hd[u],fl};
// printf("!%d %d %d %lld\n",u,v,hd[u],fl);
hd[u]=et;
e[++et]={u,hd[v],0};
hd[v]=et;
return;
}
bool bfs()
{
for(int i=1;i<=N*M+2;i++) dep[i]=MXD;
dep[S]=0;
queue<int>q;
q.push(S);
while(q.size())
{
int u=q.front();
// printf("BFS%d\n",u);
if(u==T) return 1;
q.pop();
for(int i=hd[u];i;i=e[i].nxt)
{
int v=e[i].to;
LL fl=e[i].fl;
// printf("BFS%d %d %lld %d\n",u,v,fl,dep[v]);
if(fl>0&&dep[v]==MXD)
{
dep[v]=dep[u]+1;
// puts("OOO");
q.push(v);
}
}
}
return 0;
}
LL dfs(int u,LL flow)
{
// printf("DFS%d %lld\n",u,flow);
if(u==T||flow==0) return flow;
LL res=0;
for(int i=cur[u];i;i=e[i].nxt)
{
cur[u]=i;
int v=e[i].to;
LL fl=e[i].fl;
if(fl<=0||dep[v]!=dep[u]+1) continue;
LL k=dfs(v,min(flow,fl));
e[i].fl-=k;
e[i^1].fl+=k;
res+=k;
flow-=k;
}
return res;
}
LL Dinic()
{
LL res=0;
while(bfs())
{
for(int i=1;i<=N*M+2;i++) cur[i]=hd[i];
res+=dfs(S,INF);
}
return res;
}
int Trans(int x,int y)
{
return (x-1)*M+y;
}
bool b[MAXN];
int main()
{
scanf("%d %d %d",&N,&M,&K);
for(int i=1;i<=K;i++)
{
int x,y;
scanf("%d %d",&x,&y);
b[Trans(x,y)]=1;
}
K=0;
for(int i=1;i<=N;i++)
{
for(int j=1;j<=M;j++)
{
if(i%2) Add(N*M+1,Trans(i,j),1);
else Add(Trans(i,j),N*M+2,1);
if(b[Trans(i,j)]) K++;
}
}
for(int i=1;i<=N;i++)
{
if(i%2==0) continue;
for(int j=1;j<=M;j++)
{
for(int k=0;k<8;k++)
{
int x=i+dx[k],y=j+dy[k];
if(x<1||x>N||y<1||y>M) continue;
if(b[Trans(i,j)]||b[Trans(x,y)]) continue;
Add(Trans(i,j),Trans(x,y),1);
}
}
}
S=N*M+1,T=N*M+2;
printf("%lld\n",N*M-K-Dinic());
return 0;
}
是建模的问题吗