zoukankan      html  css  js  c++  java
  • poj1466独立集

    这题一开始以为可以直接套最大独立集模板,结果发现样例都过不了。

    看了discuss后有人说是n-m/2,因为要去掉搞基的= =瞬间吓尿了,到现在还不知道他怎么看出来的。

    反正我的想法是因为题目输入使配对重复,即A和B搞暧昧与B和A搞暧昧是一样的,故求出最大匹配后要除二。

     1 #include <algorithm>
     2 #include <iostream>
     3 #include <iomanip>
     4 #include <cstring>
     5 #include <cstdlib>
     6 #include <cstdio>
     7 #include <string>
     8 #include <vector>
     9 #include <queue>
    10 #include <cmath>
    11 #include <stack>
    12 //#include <map>
    13 #include <cmath>
    14 #include <set>
    15 #include <climits>
    16 #define INF 0x7fffffff
    17 #define finc(i,a,b) for(i=a;i<=b;i++)
    18 #define fdec(i,a,b) for(i=a;i>=b;i--)
    19 #define MAXN 301
    20 #define MAXM 100002
    21 using namespace std;
    22 int t;
    23 int linker[550];
    24 int g[550][550];
    25 bool vis[550];
    26 bool dfs(int u)
    27 {
    28     int v;
    29     finc(v,0,t-1){
    30         if(!vis[v]&&g[u][v])
    31         {
    32             vis[v]=1;
    33             if(linker[v]==-1||dfs(linker[v]))
    34             {
    35                 linker[v]=u;
    36                 return true;
    37             }
    38         }
    39     }
    40     return false;
    41 }
    42 
    43 int hungary()
    44 {
    45     int u,res=0;
    46     memset(linker,-1,sizeof(linker));
    47     finc(u,0,t-1){
    48         memset(vis,0,sizeof(vis));
    49         if(dfs(u))  res++;
    50     }
    51     return res;
    52 }
    53 
    54 int main()
    55 {
    56     int n,r,u,v,i,a,p,j;
    57     while(~scanf("%d",&t)){
    58         memset(g,0,sizeof(g));
    59         finc(i,0,t-1)
    60         {
    61             scanf("%d: (%d)",&a,&n);
    62            // cout<<a<<" "<<n<<endl;
    63             finc(j,1,n)
    64             {
    65                 scanf("%d",&p);
    66                 g[a][p]=1;
    67             }
    68         }
    69         cout<<t-hungary()/2<<endl;
    70     }
    71 }
    View Code

    最经搞图论RE.TLE.OLE特别多= =老是估错范围。。。

  • 相关阅读:
    错误页面提示大全
    http协议基础知识
    初识性能测试
    seo
    测试工程师的分类和发展方向
    Jsessionid和cookie的区别与联系
    nginx配置
    复盘能力
    开发自测方法
    OKR 目标关键成果法
  • 原文地址:https://www.cnblogs.com/-dante-/p/3265991.html
Copyright © 2011-2022 走看看