Bzoj2718: [VIOLET 4] Graduation Trip

Source: Internet
Author: User
2718: [VIOLET 4] graduation trip time limit: 10 sec memory limit: 128 MB
Submit: 229 solved: 126
[Submit] [Status] Description

Input

Output

Maximum number of scenic spots

Sample input7 6
1 2
2 3
5 4
4 3
3 6
6 7

Sample output2
Hint

 

 

Source

Ctsc2008 River & Ural 1533. Fat Hobbits

Question: Same as the previous Code:
 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] Graduation Trip

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.