int cnt,s,t,n,m; int head[maxn],Next[maxn*20],to[maxn*20]; int flow[maxn*20],dep[maxn],cur[maxn],mp[405][405]; int dir[8][2]={1,2,1,-2,-1,2,-1,-2,-2,-1,-2,1,2,1,2,-1}; inline void add(int u,int v,int w){ Next[cnt]=head[u]; head[u]=cnt; to[cnt]=v; flow[cnt++]=w; Next[cnt]=head[v]; head[v]=cnt; to[cnt]=u; flow[cnt++]=0; } int dfs(int u,int cost){ if(u==t) return cost; for(int &i=cur[u];i!=-1;i=Next[i]){ if(dep[to[i]]==dep[u]+1&&flow[i]>0){ int dis=dfs(to[i],min(flow[i],cost)); if(dis>0){ flow[i]-=dis; flow[i^1]+=dis; return dis; } } } return 0; } int bfs(){ queue<int> q; q.push(s); memset(dep,0,sizeof(dep)); dep[s]=1; while(!q.empty()){ int u=q.front(); q.pop(); for(int i=head[u];i!=-1;i=Next[i]){ if(flow[i]>0&&dep[to[i]]==0){ dep[to[i]]=dep[u]+1; q.push(to[i]); } } } if(dep[t]>0) return 1; return 0; } int dicnic(){ int ans=0; while(bfs()){ int cost; for(int i=0;i<=t+2;i++){ cur[i]=head[i]; } while(cost=dfs(s,inf)) ans+=cost; } return ans; } void init(){ memset(head,-1,sizeof(head)); cnt=0; }