标签:ring temp \n lin mes cin trie break tor
啊我死了
#include<iostream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e6+10;
const int M=3e7+10;
int n,len,top,num,cnt,tot,tr[N][2],ver[M],Next[M],lin[N],dfn[N],low[N],ins[N],c[N],s[N],siz[N];
string ch[N];
vector<int>en[N];
void add(int x,int y){ver[++len]=y,Next[len]=lin[x],lin[x]=len;}
void insert(int id){
int ii;
int now=0,temp;if(id>n) ii=id-n;else ii=id;
for(int i=0;i<siz[ii];++i){
if(ch[ii][i]=='?'){
if(id>n) temp=1;
else temp=0;
}else temp=ch[ii][i]-'0';
if(!tr[now][temp]) tr[now][temp]=++tot;
now=tr[now][temp];
}en[now].push_back(id);
}
void find(int id){
int now=0,temp;int ii;
if(id>n) ii=id-n; else ii=id;
for(int i=0;i<siz[ii];++i){
for(int j=0;j<en[now].size();++j){
add(en[now][j],(id-n+2*n)%(2*n)),add(id,(en[now][j]-n+2*n)%(2*n));
}
if(ch[ii][i]=='?'){
if(id>n) temp=1;
else temp=0;
}else temp=ch[ii][i]-'0';
now=tr[now][temp];
//if(!now) break;
}
for(int j=0;j<en[now].size();++j){
if(en[now][j]!=id)
add(en[now][j],(id-n+2*n)%(2*n)),add(id,(en[now][j]-n+2*n)%(2*n));
}
}
void tarjan(int x){
s[++top]=x;ins[x]=1;
dfn[x]=low[x]=++num;
for(int i=lin[x];i;i=Next[i]){
int y=ver[i];
if(!dfn[y]){
tarjan(y);
low[x]=min(low[x],low[y]);
}else if(ins[y]) low[x]=min(low[x],dfn[y]);
}
if(dfn[x]==low[x]){
cnt++;int y;
do{
y=s[top--];ins[y]=0;c[y]=cnt;
}while(x!=y);
}
}
bool two_SAT(){
for(int i=1;i<=n;++i)
if(c[i]==c[i+n])return false;
return true;
}
int main(){
freopen("1.in","r",stdin);
scanf("%d",&n);
for(int i=1;i<=n;++i){
cin>>ch[i];
siz[i]=ch[i].size();
insert(i);
insert(i+n);
}
for(int i=1;i<=2*n;++i){
find(i);
}
for(int i=1;i<=2*n;++i) if(!dfn[i]) tarjan(i);
if(!two_SAT()){
printf("NO\n");
}else printf("YES\n");
return 0;
}
标签:ring temp \n lin mes cin trie break tor
原文地址:https://www.cnblogs.com/kgxw0430/p/10420516.html