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