NOI2010 航空管制

题目链接:戳我

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#define MAXN 2010
using namespace std;
int n,m,t,dfn_clock;
int tim[MAXN],cur[MAXN],kkk[MAXN],p[MAXN];
struct Node
{
int id,tim;
friend bool operator < (Node x,Node y)
{return x.tim<y.tim;}
};
struct Edge{int nxt,to;}edge[100010];
{
}
inline bool cmp(int x,int y){return ans1[x]<ans1[y];}
inline void solve1()
{
priority_queue<Node>q;
for(int i=1;i<=n;i++)
if(kkk[i]==0)
q.push((Node){i,tim[i]});
while(!q.empty())
{
int u=q.top().id;q.pop();
ans1[u]=dfn_clock,dfn_clock--;
{
int v=edge[i].to;
if(ans1[v]) continue;
kkk[v]--;
if(kkk[v]==0) q.push((Node){v,tim[v]});
}
}
}
inline void solve2(int x)
{
priority_queue<Node>q;
for(int i=1;i<=n;i++)
if(!kkk[i]&&i!=x)
q.push((Node){i,tim[i]});
if(q.empty()) {ans2[x]=dfn_clock;return;}
while(!q.empty())
{
int u=q.top().id; q.pop();
if(dfn_clock>tim[u]) continue;
cur[u]=dfn_clock,dfn_clock--;
{
int v=edge[i].to;
if(v==x||cur[v]) continue;
kkk[v]--;
if(kkk[v]==0)
q.push((Node){v,tim[v]});
}
}
ans2[x]=dfn_clock;
// for(int i=1;i<=n;i++) printf("cur[%d]=%d\n",i,cur[i]); puts("");
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("ce.in","r",stdin);
#endif
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) scanf("%d",&tim[i]);
for(int i=1;i<=m;i++)
{
int x,y;
scanf("%d%d",&x,&y);
ru[x]++;
}
// for(int i=1;i<=n;i++) printf("ru[%d]=%d\n",i,ru[i]);
dfn_clock=n;
memcpy(kkk,ru,sizeof(ru));
solve1();
for(int i=1;i<=n;i++) p[i]=i;
sort(&p[1],&p[n+1],cmp);
for(int i=1;i<=n;i++) printf("%d ",p[i]); puts("");
for(int i=1;i<=n;i++)
{
dfn_clock=n;
memcpy(kkk,ru,sizeof(ru));
memset(cur,0,sizeof(cur));
solve2(i);
}
for(int i=1;i<=n;i++) printf("%d ",ans2[i]); puts("");
return 0;
}

posted @ 2019-06-19 17:42  风浔凌  阅读(112)  评论(0编辑  收藏  举报