Description
Input
Output
最多可选多少景点
Sample Input
7 6
1 2
2 3
5 4
4 3
3 6
6 7
Sample Output
2
HINT
Source
Ctsc2008 River & ural 1533. Fat Hobbits
同bzoj1143
http://www.elijahqi.win/2018/01/07/bzoj1143-ctsc2008%e7%a5%ad%e7%a5%80river/
#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 440
#define inf 0x3f3f3f3f
using namespace std;
inline char gc(){
static char now[1<<16],*S,*T;
if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;}
return *S++;
}
inline int read(){
int x=0;char ch=gc();
while(ch<'0'||ch>'9') ch=gc();
while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=gc();}return x;
}
int n,m,mp[N][N],h[N],num=1,level[N],T,cur[N];
struct node{
int y,z,next;
}data[N*N*2];
inline void insert1(int x,int y,int z){
data[++num].y=y;data[num].z=z;data[num].next=h[x];h[x]=num;
data[++num].y=x;data[num].z=0;data[num].next=h[y];h[y]=num;
}
inline bool bfs(){
queue<int>q;q.push(0);memset(level,0,sizeof(level));level[0]=1;
while(!q.empty()){
int x=q.front();q.pop();
for (int i=h[x];i;i=data[i].next){
int y=data[i].y,z=data[i].z;
if(level[y]||!z) continue;level[y]=level[x]+1;if(y==T) return 1;q.push(y);
}
}return 0;
}
inline int dfs(int x,int s){
if(x==T) return s;int ss=s;
for (int &i=cur[x];i;i=data[i].next){
int y=data[i].y,z=data[i].z;
if(level[x]+1==level[y]&&z){
int xx=dfs(y,min(z,s));if (!xx) level[y]=0;
s-=xx;data[i].z-=xx;data[i^1].z+=xx;if(!s) return ss;
}
}return ss-s;
}
int main(){
//freopen("bzoj2718.in","r",stdin);
n=read();m=read();T=n*2+1;
for (int i=1;i<=m;++i){
int x=read(),y=read();mp[x][y]=1;
}
for (int k=1;k<=n;++k)
for (int i=1;i<=n;++i)
for (int j=1;j<=n;++j)
if(i!=j) mp[i][j]|=mp[i][k]&mp[k][j];
for (int i=1;i<=n;++i) insert1(0,i,1),insert1(i+n,T,1);
for (int i=1;i<=n;++i)
for (int j=1;j<=n;++j){
if (i==j||!mp[i][j]) continue;insert1(i,j+n,1);
}int ans=0;
while(bfs()) memcpy(cur,h,sizeof(h)),ans+=dfs(0,inf);printf("%d\n",n-ans);
return 0;
}