• [bzoj1242] Zju1015 Fishing Net弦图判定


      弦图判定。。MCS算法。

      先选一个点,然后每次拿 相邻已选点最多 的未选点。

      选完之后判断一下是否是完美消除序列。

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<cstring>
     4 #include<algorithm>
     5 #define ll long long
     6 using namespace std;
     7 const int maxn=1023;
     8 struct zs{int too,pre;}e[5233333];int tot,last[maxn<<1];
     9 bool con[maxn][maxn],u[maxn];
    10 int st[maxn],top,dl[maxn],tim[maxn],deg[maxn];
    11 int i,j,k,n,m,now;
    12   
    13 int ra;char rx;
    14 inline int read(){
    15     rx=getchar(),ra=0;
    16     while(rx<'0'||rx>'9')rx=getchar();
    17     while(rx>='0'&&rx<='9')ra*=10,ra+=rx-48,rx=getchar();return ra;
    18 }
    19 inline void ins(int a,int b){e[++tot].too=b,e[tot].pre=last[a],last[a]=tot;}
    20 #define f(x) x+n+1
    21 inline void mcs(){
    22     register int j;int i,mx=0,pos;
    23     for(i=1;i<=n;i++)ins(f(0),i);
    24     for(i=n;i;i--){
    25         pos=0;
    26         for(j=last[f(mx)];j&&!pos;j=e[j].pre)
    27             if(!u[e[j].too])pos=e[j].too,u[pos]=1,dl[i]=pos;
    28             else last[f(mx)]=e[j].pre;
    29         if(!pos)mx--,i++;else{
    30             for(j=last[pos];j;j=e[j].pre)if(!u[e[j].too])
    31                 deg[e[j].too]++,ins(f(deg[e[j].too]),e[j].too),mx=max(mx,deg[e[j].too]);
    32         }
    33     }
    34 }
    35 bool cmp(int a,int b){return tim[a]<tim[b];}
    36 int main(){
    37     n=read(),m=read();register int j;
    38     for(i=1;i<=m;i++)j=read(),k=read(),ins(j,k),ins(k,j),con[j][k]=con[k][j]=1;
    39     for(i=1;i<=n;i++)con[i][i]=1;
    40     mcs();
    41     for(i=1;i<=n;i++)tim[dl[i]]=i;tim[0]=1e9;
    42     for(i=n;i;i--){
    43         now=dl[i],top=0;
    44         for(j=last[now];j;j=e[j].pre)if(tim[e[j].too]>i)
    45             st[++top]=e[j].too;
    46         if(top<2)continue;int mn=0;
    47         for(j=1;j<=top;j++)if(tim[st[j]]<tim[mn])mn=st[j];
    48         for(j=1;j<=top;j++)if(!con[st[1]][st[j]]){
    49             puts("Imperfect");return 0;
    50         }
    51     }
    52     puts("Perfect");
    53 }
    View Code
  • 相关阅读:
    sqli-labs(30)
    sqli-labs(29)
    sqli-labs29-31关Background-6 服务器(两层)架构
    HA高可用的搭建
    克隆虚拟机,如何将克隆虚拟的网卡设置为eth0
    mysql1主多从配置
    关于mysql binlog日志的格式说明
    mysql主从同步
    tomcat的安装
    获取系统的IP
  • 原文地址:https://www.cnblogs.com/czllgzmzl/p/5623309.html
Copyright © 2020-2023  润新知