标签:style class blog code color get
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; #define N 2100 #define M 11000 int t[N]; int n,m; int dp[N]; int ru[N],op[N]; int e[N],ne[M],v[M]; int nn,been1[N],been2[N]; int q[N],he,bo; struct P{ int x,y; P(int a=0,int b=0){ x=a,y=b; } bool operator<(P a)const{ return y<a.y; } }rc[N]; void add(int x,int y){ ne[++nn]=e[x],e[x]=nn,v[nn]=y; } int f[N]; int tot; int get(int x){ return f[x]==x?x:f[x]=get(f[x]); } int ans[N]; int solv(int x){ memset(been1,0,sizeof(been1)); memset(been2,0,sizeof(been2)); for(int i=0;i<=n;i++)f[i]=i; been1[x]=1; int y,a1=0,a2=0; for(int j=1;j<=n;j++){ for(int i=e[y=op[j]];i;i=ne[i]){ if(been1[y])been1[v[i]]=1; } if(been1[y])a1++; } been2[x]=1; for(int j=n;j>=1;j--){ for(int i=e[y=op[j]];i;i=ne[i]){ if(been2[v[i]])been2[y]=1; } if(been2[y])a2++; } for(int i=1;i<=n;i++){ if(!been1[i]&&!been2[i]){ y=get(dp[i]); f[y]=get(y-1); } } int now=n+1; for(int i=1;i<=a2;i++){ now=get(now-1); } return now; } int main(){ scanf("%d%d",&n,&m); for(int i=1;i<=n;i++)scanf("%d",&t[i]),t[i]=min(t[i],n),dp[i]=t[i]; for(int i=1;i<=m;i++){ int a,b; scanf("%d%d",&a,&b); add(b,a); ru[a]++; } he=0; bo=1; int x; for(int i=1;i<=n;i++)if(!ru[i])q[++he]=i; while(he>=bo){ x=q[bo++]; rc[x]=P(x,dp[x]); op[++tot]=x; for(int i=e[x];i;i=ne[i]){ ru[v[i]]--; dp[v[i]]=min(dp[v[i]],dp[x]-1); if(!ru[v[i]])q[++he]=v[i]; } } sort(rc+1,rc+n+1); for(int i=1;i<=n;i++)printf("%d ",rc[i].x); printf("\n"); for(int i=1;i<=n;i++)printf("%d ",solv(i)); }
[Noi2010]Plane 航空管制 贪心,布布扣,bubuko.com
标签:style class blog code color get
原文地址:http://www.cnblogs.com/wangyucheng/p/3796541.html