zoukankan      html  css  js  c++  java
  • LG 2341 受欢迎的牛

    SCC
    再DFS一下
    即可

    不过为什么我代码在
    BZOJ RE
    LG+O2 WA
    LG AC

    诡异诡异

    #include <cstdio>
    
    int read(){
        int x=0, f=1;char ch=getchar();
        while(ch<'0' || ch>'9'){if(ch=='-')f=-f;ch=getchar();}
        while(ch>='0' && ch<='9'){x=x*10+(ch-'0');ch=getchar();}
        return x*f;
    }
    
    const int MAXV=10111;
    const int MAXE=50111;
    
    int N, M;
    
    struct Vert{
        int FE;
        bool Vis;
        int Bel;
    } V[MAXV];
    
    struct Edge{
        int x, y, next;
        bool i;
    } E[MAXE<<1];
    
    int Ecnt=0;
    
    void addE(int a, int b){
        ++Ecnt;
        E[Ecnt].x=a;E[Ecnt].y=b;E[Ecnt].next=V[a].FE;V[a].FE=Ecnt;E[Ecnt].i=false;
        ++Ecnt;
        E[Ecnt].x=b;E[Ecnt].y=a;E[Ecnt].next=V[b].FE;V[b].FE=Ecnt;E[Ecnt].i=true;
    }
    
    void Vis_init(){
        for(int i=1;i<=N;++i)
            V[i].Vis=false;
    }
    
    int Dfn[MAXV], DFN=0;
    
    void DFS(int at){
        V[at].Vis=true;
        for(int k=V[at].FE, to;k>0;k=E[k].next){
            if(E[k].i)	continue;
            to=E[k].y;
            if(/*!*/V[to].Vis)	continue;
            DFS(to);
        }
        Dfn[++DFN]=at;
    }
    
    void DFS(int at, int b){
        V[at].Vis=true;
        for(int k=V[at].FE, to;k>0;k=E[k].next){
            if(!E[k].i)	continue;
            to=E[k].y;
            if(/*!*/V[to].Vis)	continue;
            DFS(to, b);
        }
        V[at].Bel=b;
    }
    
    int Bcnt=0;
    
    void scc(){
        Vis_init();
        for(int i=1;i<=N;++i){
            if(V[i].Vis)	continue;
            DFS(i);
        }
        Vis_init();
        for(int i=N, j;i>=1;--i){
            j=Dfn[i];
            if(V[j].Vis)	continue;
            DFS(j, ++Bcnt);
        }
    }
    
    bool Win=true;
    int ANS=0;
    
    int main(){
        
        N=read();M=read();
        for(int i=1, a, b;i<=M;++i){
            a=read();b=read();
            addE(b, a);
        }
        
        scc();
        
        Vis_init();
        DFS(Dfn[N]);
        
        for(int i=1;i<=N;++i){
            if(!V[i].Vis){
                Win=false;
                break;
            }
        }
        
        if(Win){
            for(int i=1;i<=N;++i){
                if(V[i].Bel==1)	++ANS;
            }
            printf("%d
    ", ANS);
        }
        else	puts("0");
        
        return 0;
    }
    
    
  • 相关阅读:
    strict aliasing
    加密数据包加解密部分逆向跟踪
    自定义session扫描器
    同步容器类ConcurrentHashMap及CopyOnWriteArrayList
    CountDownLatch闭锁
    volatile关键字与内存可见性
    原子变量与CAS算法
    C语言笔记一
    小组讨论4
    201920201学期 20192416《网络空间安全专业导论》第六周学习总结
  • 原文地址:https://www.cnblogs.com/Pickupwin/p/9096147.html
Copyright © 2011-2022 走看看