Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
无偿贴出rank2代码/* ID:huangta3 PROG: LANG:C++ */ #include <iostream> #include <cstring> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <list> #include <queue> #include <vector> #include <ctime> #include <set> #include <bitset> #include <deque> #include <fstream> #include <stack> #include <map> #include <utility> #include <cassert> #include <string> #include <iterator> #include <cctype> using namespace std; const int maxn=2003; const int maxm=4000003; int n,m,tot=0,N,Link[maxn],pre[maxm],t[maxm],dfn[maxn],low[maxn],stk[maxn],vis[maxn],belong[maxn],top=0,ind=0; int get() { int f=0,v=0;char ch; while(!isdigit(ch=getchar()))if(ch=='-')break; if(ch=='-')f=1;else v=ch-48; while(isdigit(ch=getchar()))v=v*10+ch-48; if(f==1)return -v;else return v; } int op(int x) { if(x<=n)return x+n;else return x-n; } void add(int x,int y) { pre[++tot]=Link[x]; Link[x]=tot; t[tot]=y; } void init() { n=get(),m=get(); for(int i=1;i<=m;i++) { int x=get(),y=get(),z=get(); char ch; x++,y++; while(!isalpha(ch=getchar())); if(ch=='A'&&z==0)add(x,op(y)),add(y,op(x)); if(ch=='A'&&z==1)add(op(x),x),add(op(y),y); if(ch=='O'&&z==0)add(x,op(x)),add(y,op(y)); if(ch=='O'&&z==1)add(op(x),y),add(op(y),x); if(ch=='X'&&z==0)add(x,y),add(y,x),add(op(x),op(y)),add(op(y),op(x)); if(ch=='X'&&z==1)add(x,op(y)),add(op(x),y),add(y,op(x)),add(op(y),x); } } void tarjan(int x) { dfn[x]=low[x]=++ind; vis[x]=1; stk[++top]=x; for(int i=Link[x];i>0;i=pre[i]) { if(vis[t[i]]==0) { tarjan(t[i]); low[x]=min(low[x],low[t[i]]); }else if(vis[t[i]]==1)low[x]=min(low[x],low[t[i]]); } if(dfn[x]==low[x]) { N++; while(stk[top]!=x)belong[stk[top]]=N,vis[stk[top--]]=2; belong[stk[top]]=N,vis[stk[top--]]=2; } } void work() { N=0; for(int i=1;i<=n+n;i++) if(vis[i]==0)tarjan(i); for(int i=1;i<=n;i++) if(belong[i]==belong[op(i)]){puts("NO");return;} puts("YES"); } int main() { init(); work(); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator