zoukankan      html  css  js  c++  java
  • 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

    题解:
    同上一题
    代码:
     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 1000000000
    12 #define maxn 110
    13 #define maxm 500+100
    14 #define eps 1e-10
    15 #define ll long long
    16 #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-ans);
    60     return 0; 
    61 }
    View Code
  • 相关阅读:
    向IPython Notebook中导入.py文件
    python--时间日期
    python--条件和循环
    python--输入输出
    python--字符串
    python--内置函数
    python--异常
    python--模块
    python--数据结构
    pybrain
  • 原文地址:https://www.cnblogs.com/zyfzyf/p/3938007.html
Copyright © 2011-2022 走看看