HDU 1848 2SAT Output Dictionary order minimum

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.