玄学全RE?

P4171 [JSOI2010] 满汉全席

中二病 @ 2019-08-25 23:13:28

#include<iostream>
#include<cstdio>
#include<vector>
#include<stack> 

using namespace std;

const int N=10010;

vector <int> edge[N];
stack <int> s;

int n,m,dish[5][N],dfn[N],low[N],t,color[N];
char ch;

void add(int u,int v){
    edge[u].push_back(v);
}

void clear(){
    while(!s.empty())s.pop();
    for(int i=1;i<1000;i++){
        edge[i].clear();
        dish[0][i]=dish[1][i]=dfn[i]=color[i]=low[i]=0;
    }
}

int tot,c_tot;
bool bo[N];

void tarjan(int u){
    dfn[u]=low[u]=++tot;
    s.push(u);bo[u]=1;
    for(int i=0;i<edge[u].size();i++){
        int v=edge[u][i];
        if(!dfn[v]){
            tarjan(v);low[u]=min(low[u],low[v]);
        }
        else{
            if(bo[v])low[u]=min(low[u],dfn[v]);
        }
    }
    if(low[u]==dfn[u]){
        int k=0;c_tot++;
        while(k!=u){
            k=s.top();s.pop();
            bo[k]=0;color[k]=c_tot;
        }
    } 
}

int main(){
    cin>>t;int x,y,k1,k2;
    while(t){
        t--;clear();cin>>n>>m;
        for(int i=1;i<=m;i++){
            cin>>ch>>x;k1=(ch=='m')?1:0;
            cin>>ch>>x;k2=(ch=='m')?1:0;
            add(x+(k1^1)*n,y+k2*n);add(y+(k2^1)*n,x+k1*n);
        }
        for(int i=1;i<=n*2;i++){
            if(!dfn[i])tarjan(i);
        }
        bool flag=0;
        for(int i=1;i<=n;i++){
            if(color[i]==color[i+n])flag=1;
        }
        if(flag==1)cout<<"BAD"<<endl;
        else cout<<"GOOD"<<endl;
    }
    return 0;
}

by s_ShotღMaki @ 2019-08-25 23:31:24

您别学了您都无敌了


|