20pts求助,RE+WA玄关
查看原帖
20pts求助,RE+WA玄关
710862
thrX楼主2024/10/21 16:03

CODE:

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+24;
int n,m,a,va,b,vb;
vector<int> E[maxn<<2];
int dfn[maxn<<2],low[maxn<<2],stk[maxn<<2],co[maxn<<2],col,top,num;
inline void tarjan(int u){
    dfn[u]=low[u]=++num;
    stk[++top]=u;
    for(auto v:E[u]){
        if(!dfn[v]){
            tarjan(v);
            low[u]=min(low[u],low[v]);
        }else if(!co[v]){
            low[u]=min(low[u],dfn[v]);
        }
    }
    if(dfn[u]==low[u]){
        co[u]=++col;
        while(stk[top]!=u){
            co[stk[top]--]=col;
        } 
        top--;
    }
}
void add(int u,int v){
    E[u].push_back(v);
}
int main(){
    
    cin>>n>>m;
    for(int i=0;i<m;++i){
        cin>>a>>va>>b>>vb;
        if(va==0&&vb==0){
            add(a+n,b);
            add(b+n,a);
        }
        if(va==0&&vb==1){
            add(a+n,b+n);
            add(b,a); 
        }
        if(va==1&&vb==0){
            add(a,b);
            add(b+n,a+n);
        }
        if(va==1&&vb==1){
            add(a,b+n); 
            add(b,a+n); 
        }
    }
    for(int i=1;i<=(n<<1);i++)if(!dfn[i])tarjan(i);
    for (int i=1;i<=n;i++)
        if(co[i]==co[i+n]){
            puts("IMPOSSIBLE");
            exit(0);
        }
    puts("POSSIBLE");
    for(int i=1;i<=n;++i)cout<<(co[i]>co[i+n])<<' ';
    cout<<'\n';
    
    return 0;
}

不知道为什么会错,尤其是RE

2024/10/21 16:03
加载中...