Two-point answer + 2-SAT judgment
#include <cstdio>#include<cstring>#include<cmath>#include<vector>#include<algorithm>using namespacestd;Const intmaxn=8000+5;intm,n,t;intans;intL,r,mid;inta[10010],b[10010],c[10010];structtwosat{intN; Vector<int> g[maxn*2]; BOOLmark[maxn*2]; ints[maxn*2],c; BOOLDfsintx) {if(mark[x^1])return false; if(Mark[x])return true; MARK[X]=true; S[c++]=x; for(intI=0; I<g[x].size (); i++) if(!dfs (G[x][i]))return false; return true; } voidInitintN) { This->n=N; for(intI=0; i<n*2; i++) g[i].clear (); memset (Mark,0,sizeofmark); } voidAdd_clause (intXinty) {g[x].push_back (y^1); G[y].push_back (x^1); } BOOLsolve () { for(intI=0;i<2*n;i+=2) if(!mark[i]&&!mark[i+1]) {c=0; if(!DFS (i)) { while(c>0) mark[s[--c]]=false; if(!dfs (i+1))return false; } } return true; }};intMain () {scanf ("%d",&T); while(t--) {scanf ("%d%d",&n,&l); for(intI=0; i<m;i++) scanf ("%d%d%d",&a[i],&b[i],&C[i]); L=0, r=M; while(l<=R) {Mid= (l+r)/2; Twosat T; T.init (N); for(intI=0; i<mid;i++) { if(c[i]==2) {T.add_clause (2*a[i]+1,2*b[i]+1); } Else if(c[i]==1) {T.add_clause (2*a[i]+1,2*B[i]); T.add_clause (2*a[i],2*b[i]+1); } Else if(c[i]==0) {T.add_clause (2*a[i],2*B[i]); } } if(T.solve ()) {ans=Mid; L=mid+1; } Elser=mid-1; } printf ("%d\n", ans); } return 0;}
HDU 3715 Go Deeper