UVALive 3713 Astronauts

Source: Internet
Author: User

UVALive 3713 Astronauts

Question:

There are n astronauts who need to complete three types of tasks A, B, and C. Age> = average age can be A and C age. <平均年龄的能做b和c 且宇航员之间有讨厌关系不能一起做任务 要求给出一种分配方案< p>

Ideas:

A class-one person has two options and must select one. Therefore, 2-sat is used to establish edge based on age and annoying relationship, and then the feasibility is determined first. Then, any group of feasible solutions can be obtained without the minimum Lexicographic Order.

Code:

#include
 
  #include
  
   #include#include
   
    using namespace std;#define N 200010struct edge{    int u,v,next;}ed[N*4];int n,m,tot,top,cnt,idx;int dfn[N],low[N],st[N],instack[N],belong[N],head[N],f[N],col[N],in[N],qu[N],opt[N];void tarjan(int u){    int i,v;    dfn[u]=low[u]=++idx;    instack[u]=1;    st[++top]=u;    for(i=head[u];~i;i=ed[i].next)    {        v=ed[i].v;        if(dfn[v]==-1)        {            tarjan(v);low[u]=min(low[u],low[v]);        }        else if(instack[v]&&dfn[v]
    
     >1);        for(i=0;i
     
      tmp) f[i]=1;            else f[i]=2;            f[i+1]=3;        }        if(can())        {            solve();            for(i=0;i
      
       

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.