首页 > 代码库 > BZOJ2718: [Violet 4]毕业旅行

BZOJ2718: [Violet 4]毕业旅行

2718: [Violet 4]毕业旅行

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 229  Solved: 126
[Submit][Status]

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

题解:
同上一题
代码:
 1 #include<cstdio> 2 #include<cstdlib> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<iostream> 7 #include<vector> 8 #include<map> 9 #include<set>10 #include<queue>11 #define inf 100000000012 #define maxn 11013 #define maxm 500+10014 #define eps 1e-1015 #define ll long long16 #define pa pair<int,int>17 using namespace std;18 inline int read()19 {20     int x=0,f=1;char ch=getchar();21     while(ch<0||ch>9){if(ch==-)f=-1;ch=getchar();}22     while(ch>=0&&ch<=9){x=10*x+ch-0;ch=getchar();}23     return x*f;24 }25 int p[maxn],n,m,f[maxn][maxn];26 bool v[maxn];27 bool find(int x)28 {29     for(int i=1;i<=n;i++)30     if (f[x][i])31      if(!v[i])32      {33          v[i]=1;34          if(!p[i]||find(p[i]))35          {36              p[i]=x;37              return 1;38          }39      }40     return 0; 41 }42 int main()43 {44     freopen("input.txt","r",stdin);45     freopen("output.txt","w",stdout);46     n=read();m=read();47     int x,y;48     while(m--)x=read(),y=read(),f[x][y]=1;49     for(int k=1;k<=n;k++)50      for(int i=1;i<=n;i++)51       for(int j=1;j<=n;j++)52        f[i][j]=f[i][j]||(f[i][k]&&f[k][j]);53     int ans=0;  54     for(int i=1;i<=n;i++)55      {56          memset(v,0,sizeof(v));57          if(find(i))ans++;58      }   59     printf("%d\n",n-ans);60     return 0; 61 }
View Code

 

BZOJ2718: [Violet 4]毕业旅行