http://www.lydsy.com/JudgeOnline/problem.php?id=2535
Idea: for 1, we only need each point bigger than the precursor can be, and then meet as best as possible.
For the second question, let's first find out how many of these precursors are ans,cnt=ans.
Every access to an unreachable point, cnt++
Then for the back of the point from the small to the big row, if there is K>ans, then must be in our current processing of this point before, ans++
If there is a k<=cnt, I will be placed at the back of this point, so ans=k+1
Remember not to save the convenience of Add (read (), read ()), as if it would be an error.
1#include <algorithm>2#include <cstdio>3#include <cmath>4#include <cstring>5#include <iostream>6 structnode{7 intK,id;8}p[200005];9 inttot=0, go[200005],next[200005],first[200005];Ten inta[200005],n,m,vis[200005],cnt; One intRead () { A intt=0, f=1;CharCh=GetChar (); - while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} - while('0'<=ch&&ch<='9') {t=t*Ten+ch-'0'; ch=GetChar ();} the returnt*F; - } - voidInsertintXinty) { -tot++; +go[tot]=y; -next[tot]=First[x]; +first[x]=tot; A } at voidAddintXinty) { - Insert (x, y); insert (y,x); - } - voidinit () { -N=read (); m=read (); - for(intI=1; i<=n;i++) P[i].k=read (), p[i].id=i; in for(intI=1; i<=m;i++){ - intX=read (), y=read (); to Add (x, y); + } - } the BOOLCMP (node Q,node w) { * returnq.k<W.K; $ }Panax Notoginseng BOOLDealintx) { - for(intI=first[x];i;i=Next[i]) { the if(i&1){ + intPur=Go[i]; AP[x].k=std::min (p[x].k,p[pur].k-1); the } + } - } $ voidsolve1 () { $ for(intj=1; j<=n;j++) - for(intI=1; i<=n;i++) - deal (i); theStd::sort (p+1, p+1+n,cmp); - for(intI=1; i<n;i++) printf ("%d", p[i].id);Wuyiprintf"%d\n", p[n].id); the } - intCountintx) { Wu intres=0; vis[x]=1; - for(intI=first[x];i;i=Next[i]) { About intPur=Go[i]; $ if(!vis[pur]&& (i%2==0)){ -res+=count (PUR); - } - } A returnres+1; + } the voidsolve2 () { - for(intI=1; i<=n;i++){ $memset (Vis,0,sizeofvis); the intans=count (i); theCnt=ans; the for(intj=1; j<=n;j++) the if(!Vis[p[j].id]) { -cnt++; in if(P[j].k<=ans) ans++; the Else if(CNT>P[J].K) ans=p[j].k+1; the } Abouta[i]=ans; the } the for(intI=1; i<n;i++) printf ("%d", A[i]); theprintf"%d\n", A[n]); + } - voidWork () { the solve1 ();Bayi solve2 (); the } the intMain () { - init (); - Work (); the}
Bzoj 2535 Plane Aviation Control 2