"2-sat (two DFS edition)" bzoj1823-[jsoi2010] Feast

Source: Internet
Author: User

"The main topic"

There are n materials, m judges. Each material can be used to make Manchu or Han Chinese cuisine, and M judges have two kinds of guesses that will satisfy him. Q. Can I meet all the judges ' requirements?

Ideas

Can only do three questions a day, I have been a wreck ... (Ge ping lying. jpg)

Bare 2-sat, first wrote a two times DFS, speed slightly slow ... 24ms?

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5#include <vector>6 using namespacestd;7 Const intmaxn= $+ -;8vector<int>E[MAXN];9vector<int>RE[MAXN];Tenvector<int>vs; One intCMP[MAXN],VIS[MAXN]; A intcnt,n,m; -  - voidAddedge (intUintv) the { - E[u].push_back (v); - re[v].push_back (u); - } +  - voidDfsintu) + { Avis[u]=1; at      for(intI=0; I<e[u].size (); i++) -     { -         intv=E[u][i]; -         if(!Vis[v]) Dfs (v); -     } - vs.push_back (u); in } -  to voidRdfsintUintt) + { -vis[u]=1; thecmp[u]=T; *      for(intI=0; I<re[u].size (); i++) $     {Panax Notoginseng         intv=Re[u][i]; -         if(!Vis[v]) Rdfs (v,t); the     } + } A  the voidInit () + { -      for(intI=0; i<maxn;i++) vector<int>(). Swap (E[i]); $      for(intI=0; i<maxn;i++) vector<int>(). Swap (Re[i]); $scanf"%d%d",&n,&m); -      for(intI=0; i<m;i++) -     { the         Charc1,c2; -         intX,y,fx,fy;Wuyi GetChar (); thescanf"%c%d%c%d",&c1,&x,&c2,&y); -         if(c1=='m') Fx=x+n;Elsefx=x; Wu         if(c2=='m') Fy=y+n;Elsefy=y; -         if(c1=='h') Addedge (X+N,FY);Else if(c1=='m') Addedge (x,fy); About         if(c2=='h') Addedge (Y+N,FX);Else if(c1=='m') Addedge (Y,FX); $     } - } -  - voidSolve () A { +memset (Vis,0,sizeof(Vis)); the      for(intI=1; i<=n;i++)if(!Vis[i]) DFS (i); -memset (Vis,0,sizeof(Vis)), cnt=0; $      for(intI=vs.size ()-1; i>=0; i--) the         if(!vis[vs[i]]) Rdfs (vs[i],++CNT); the } the  the voidGet_ans () - { in      for(intI=1; i<=n;i++) the         if(cmp[i]==cmp[i+N]) the         { AboutPuts" Bad"); the             return; the         } thePuts"Good"); + }  -  the intMain ()Bayi { the     intT; thescanf"%d",&T); -      while(t--) -     { the init (); the solve (); the Get_ans (); the     } -     return 0; the}

"2-sat (two DFS edition)" bzoj1823-[jsoi2010] Feast

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.