Topic look half: "woc bare $ 2-sat $ white to ??"
After reading: "... ???"
If there is no restriction $ f $, that is a white to a $ 2-sat $ problem, but now there is this limit ...
Direct enumeration of $ f $ Obviously not, considering the $ f $ also included $ 2-sat $ model we built
For a limited $ [l, r] $ station, if we select it, then all $ r '$ $ L is smaller than the station and $ $ l' $ R & lt station is greater than $ $ are not selected
So a form of violence is twenty-two enumeration to see if the conflict is clearly still $ T $ Fly
Taking into account a $ ri> rj $, $ RI $ and station conflicts must likewise RJ $ and $ conflict, consider building dummy node chain $ np [] $, $ np [i] $ connected to $ np [i + 1] $
For $ ri $, corresponding to the nodes of the virtual link $ np [ri] $, then for each point of $ X $ $ rx $, $ X $ side even to $ np [rx + 1] $, for each point X $ $ $ a $ LX connected side $ np [lx] $ to $ m + x $
(Where $ m $ and $ m $ subject is not the same, obviously represents $ m + x $ $ X $ is not selected, $ X $ $ X $ represents optional)
After this composition, if $ X $ is selected, then all greater than $ $ $ Li RX node $ $ I $, will be connected to $ m + i $ (i.e., not selected)
For $ l $ limit is almost the same structure, they painted a picture of it
Specific reference code implementation DTSBT , when the code that implements the operation is relatively Sao depends know how to think about it (for me ...)
The array size to a little note, do not like me indiscriminate
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> #include<vector> using namespace std; typedef long long ll; inline int read() { int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); } return x*f; } const int N=2e6+7; int n,m,p,q,L[N],R[N]; vector <int> Tl[N],Tr[N]; int fir[N],from[N<<1],to[N<<1],cntt; inline void add(int a,int b) { from[++cntt]=fir[a]; fir[a]=cntt; to[cntt]=b; } int dfn[N],low[N],dfs_clock,bel[N],tot,st[N],Top; void Tarjan(int x) { dfn[x]=low[x]=++dfs_clock; st[++Top]=x; for(int i=fir[x];i;i=from[i]) { int &v=to[i]; if(!dfn[v]) Tarjan(v),low[x]=min(low[x],low[v]); else if(!bel[v]) low[x]=min(low[x],dfn[v]); } if(low[x]==dfn[x]) { tot++; while(st[Top]!=x) bel[st[Top--]]=tot; bel[st[Top--]]=tot; } } int main() { n=read(),m=read(),p=read(),q=read(); int a,b; for(int i=1;i<=n;i++) { a=read(),b=read(); add(m+a,b); add(m+b,a); } for(int i=1;i<=m;i++) { L[i]=read(),R[i]=read(); Tl[L[i]].push_back(i); Tr[R[i]].push_back(i); } for(int i=1;i<=q;i++) { a=read(),b=read(); add(a,m+b); add(b,m+a); } int cnt=m*2,ta=++cnt,tb=++cnt; for(int i=1;i<=p;i++) { for(auto x: Tl[i]) add(x,ta),add(tb,m+x); for(auto x: Tr[i]) { cnt++; add(cnt,ta); add(cnt,m+x); ta=cnt; cnt++; add(tb,cnt); add(x,cnt); tb=cnt; } } for(int i=1;i<=2*m;i++) if(!dfn[i]) Tarjan(i); for(int i=1;i<=m;i++) if(bel[i]==bel[m+i]) { printf("-1\n"); return 0; } int ans=0; vector <int> V; for(int i=1;i<=m;i++) if(bel[i]<bel[i+m]) ans=max(ans,L[i]),V.push_back(i); printf("%d %d\n",int(V.size()),ans); for(auto x: V) printf("%d ",x); printf("\n"); return 0; }