# [BZOJ2109] [Noi2010]Plane 航空管制

### 样例输入 Sample Input###

5 5
4 5 2 5 4
1 2
3 2
5 1
3 4
3 1


### 样例输出 Sample Output###

3 4 1 2 1


### 数据范围及提示 Data Size & Hint###

$n≤2,000，m≤10,000$

### 代码###

#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<queue>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long LL;
typedef pair<int,int> PII;
#define X first
#define Y second
{
int x=0,f=1;char c=getchar();
while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c)){x=x*10+c-'0';c=getchar();}
return x*f;
}
const int maxn=2010,maxm=10010;
struct Edge
{
int u,v,next;
Edge() {}
Edge(int _1,int _2,int _3):u(_1),v(_2),next(_3) {}
}e[maxm];
int n,m,ce=-1,first[maxn],a[maxn],x,y,s[maxn],top,r[maxn],R[maxn];
priority_queue <PII,vector<PII>,greater<PII> > Q;
int calc(int cur)
{
int now=1;
mem(s,0);top=0;while(Q.size())Q.pop();
for(int i=1;i<=n;i++)R[i]=r[i];
for(int i=1;i<=n;i++)if(R[i]==0 && i!=cur)Q.push(make_pair(a[i],i));
while(Q.size() && Q.top().X<=now)
{
s[++top]=Q.top().Y;
Q.pop();
now++;
}
while(top)
{
int x=s[top--];
for(int i=first[x];i!=-1;i=e[i].next)
{
R[e[i].v]--;
if(!R[e[i].v] && e[i].v!=cur)Q.push(make_pair(a[e[i].v],e[i].v));
}
while(Q.size() && Q.top().X<=now)
{
s[++top]=Q.top().Y;
Q.pop();
now++;
}
}
return now;
}
int main()
{
mem(first,-1);
for(int i=1;i<=n;i++)
{
if(i>1)putchar(' ');
printf("%d",n-calc(i)+1);
}
putchar('\n');
return 0;

}


### 总结###

posted @ 2019-11-25 13:59  小飞淙的云端  阅读(75)  评论(0编辑  收藏