Tells you the sequence of 22 collisions, so that the output dictionary order is minimal.
The first honest Tarjan, finished writing found behind completely can not be good, because chose the first point, you have no way to quickly find out all the opposing group, can only find the opposite group in a pair, and cannot find a given that random opposition group. So directly from 1 start dyeing, do not get out on the dye 2. And so on
Another lesson of the problem is that it should be opened one more times, and the side will be opened one more times. Always forget ...
#include <algorithm>#include<iostream>#include<cstdio>#include<cstring>#include<vector>#include<stack>#include<cmath>#include<cstdlib>using namespacestd;Const intmaxn=16010;structnode{intv; intNXT;}; Node edge[40100];//Number of sidesintHEAD[MAXN];intCLO[MAXN];intdirty[maxn],dirtop=0;intn,m;intCnt=0;voidAdd_edge (intUintv) {EDGE[CNT].V=v; EDGE[CNT].NXT=Head[u]; Head[u]=CNT; CNT++;}intDfsintu) {Clo[u]=1; Clo[u^1]=2; Dirty[dirtop++]=u; for(inti=head[u];i!=-1; i=edge[i].nxt) { intv=edge[i].v; if(clo[v]==1)Continue; if(clo[v]==2||! DFS (v))return 0; }}intsolve () {memset (CLO,0,sizeof(CLO)); for(intI=0; i<2*n; i+=2) { if(!Clo[i]) {Dirtop=0; if(!DFS (i)) { for(intI=0; i<dirtop;i++) clo[dirty[i]]=clo[dirty[i]^1]=0; if(!dfs (i+1))return 0; } } } return 1;}intMain () { while(SCANF ("%d%d", &n,&m)! =EOF) {CNT=0; memset (Head,-1,sizeof(head)); while(m--) { intt1,t2; scanf ("%d%d",&t1,&T2); --t1,--T2; Add_edge (T1,t2^1); Add_edge (T2,t1^1); } if(!solve ()) printf ("nie\n"); Else { for(intI=0;i<2*n;i++) { if(clo[i]==1) {printf ("%d\n", i+1); } } } } return 0;}
HDU 1848 2SAT Output Dictionary order minimum