Topic Portal: QWQ
Analysis
2-sat template (but spicy chicken as I still tune for a long time)
Code
//Bzoj 1823 2-sat#include <bits/stdc++.h>using namespaceStd;inlineintRead () {intx=0, f=1;CharCh=GetChar (); while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}int Get(){ intXCharC=GetChar (); while(c!='m'&&c!='h') c=GetChar (); if(c=='m') X=read () *2;ElseX=read () *2-1; returnx;}structedge{int from, to;}; Vector<int> g[20005];intlow[4005], dfn[4005], sccno[4005], Dfs_clock, Scc_num;stack<int>s;voidInsertintUintv) {G[u].push_back (v);}voidTarjan (intu) {Dfn[u]=low[u]=++dfs_clock; S.push (U); for(intI=0; I<g[u].size (); i++){ intv=G[u][i]; if(!Dfn[v]) {Tarjan (v); Low[u]=min (Low[u], low[v]); }Else if(!Sccno[v]) {Low[u]=min (Low[u], dfn[v]); } } if(low[u]==Dfn[u]) {Scc_num++; for(;;) { intx=s.top (); S.pop (); SCCNO[X]=Scc_num; if(X==u) Break; } }}intMain () {intn,m,t=read (); while(t--) { while(!s.empty ()) S.pop (); N=read (); m=read (); intX,y,xp,yp; for(intI=0; i<m;i++) {x=Get(); y=Get(); if(%2==0) xp=x--; Elsexp=x++; if(y%2==0) yp=y--; Elseyp=y++; Insert (xp,y); Insert (YP,X); } memset (DFN,0,sizeof(DFN)); memset (Sccno,0,sizeof(SCCNO)); Dfs_clock=scc_num=0; for(intI=1; i<=2*n;i++) if(!Dfn[i]) Tarjan (i); BOOLflag=1; for(intI=1; i<=n;i++) if(sccno[2*i]==sccno[2*i-1]) flag=false; if(flag) puts ("Good"); ElsePuts" Bad"); for(intI=0; i<=2*n;i++) g[i].clear (); } return 0;}
"Bzoj" 1823: [JSOI2010] Feast (2-SAT)