Title: http://www.lydsy.com/JudgeOnline/problem.php?id=2535
Reverse the diagram, sort the topology, use and check set to maintain the current weight can be placed in the largest position. For the second question, it is equivalent to I ban the point I cut off and then go to find the last!ans[i] position. Then the first question is which point is not ban.
#include <cstring>#include<cctype>#include<cstdio>#include<algorithm>#include<cmath>#include<queue>#defineRep (i,l,r) for (int i=l;i<=r;i++)#defineDown (i,l,r) for (int i=l;i>=r;i--)#defineCLR (x, y) memset (x,y,sizeof (×))#definell Long Long#defineMAXN 2005#defineMM Int (1e9+7)using namespacestd;structedge{intObj,pre;} e[200500];intANS[MAXN],MN[MAXN],D[MAXN],T[MAXN],HEAD[MAXN],DD[MAXN],FA[MAXN],Q[MAXN];intN,m,x,y,tot,cnt,ban;voidInsertintXinty) {e[++tot].obj=y; E[TOT].PRE=HEAD[X]; head[x]=tot;}intRead () {intx=0, f=1;CharCh=GetChar (); while(!isdigit (CH)) {if(ch=='-') f=-1; Ch=GetChar ();} while(IsDigit (CH)) {x=x*Ten+ch-'0'; Ch=GetChar ();} returnx*F;}int Get(intx) { if(fa[x]==x)returnx; returnfa[x]=Get(Fa[x]);}voiddpintban) {Rep (i,1, N) d[i]=dd[i],fa[i]=i,ans[i]=0, Mn[i]=min (N,t[i]); Cnt=0; Rep (I,1, N)if(!d[i]) q[++cnt]=i; while(CNT) {intu=q[cnt--]; if(U==ban)Continue; intpos=Get(Mn[u]); Ans[pos]=u; fa[pos]=pos-1; for(intj=head[u];j;j=e[j].pre) { intV=e[j].obj; d[v]--; MN[V]=min (mn[v],mn[u]); if(!d[v]) q[++cnt]=v; } }}intMain () {n=read (); m=read (); Rep (I,1, N) t[i]=read (); Rep (I,1, M) {x=read (); y=read (); Insert (Y,X); DD[X]++; } DP (0); Rep (I,1, N-1) printf ("%d", Ans[i]); printf"%d\n", Ans[n]); Rep (I,1, N) {DP (i); Down (J,n,1)if(!Ans[j]) {printf ("%d%c", J,i==n?'\ n':' '); Break; } } return 0; }
BZOJ2535: [Noi2010]plane Aviation Control 2