标签:
#include<cstdio> #include<cctype> #include<queue> #include<cstring> #include<algorithm> #define rep(i,s,t) for(int i=s;i<=t;i++) #define dwn(i,s,t) for(int i=s;i>=t;i--) #define ren for(int i=first[x];i;i=next[i]) using namespace std; const int BufferSize=1<<16; char buffer[BufferSize],*head,*tail; inline char Getchar() { if(head==tail) { int l=fread(buffer,1,BufferSize,stdin); tail=(head=buffer)+l; } return *head++; } inline int read() { int x=0,f=1;char c=Getchar(); for(;!isdigit(c);c=Getchar()) if(c==‘-‘) f=-1; for(;isdigit(c);c=Getchar()) x=x*10+c-‘0‘; return x*f; } const int maxn=2010; const int maxm=10010; int n,m,ans[maxn]; struct Pair { int v,p; bool operator < (const Pair& ths) const {return v<ths.v;} }A[maxn]; int p[maxn],q[maxn],first[maxn],deg[maxn],in[maxn],next[maxm],to[maxm],e; void AddEdge(int u,int v) {deg[v]++;to[++e]=v;next[e]=first[u];first[u]=e;} int solve(int k) { rep(i,1,n) in[i]=deg[i]; int cur=1,l=1,r=0,x,res; rep(j,1,n) { while(cur<=n&&A[cur].v<=j) { if(!in[A[cur].p]&&A[cur].p!=k) q[++r]=A[cur].p; cur++; } if(l<=r) x=q[l++]; else return j; ans[j]=x; ren { in[to[i]]--; if(!in[to[i]]&&p[to[i]]<=j&&to[i]!=k) q[++r]=to[i]; } } return res; } int main() { n=read();m=read(); rep(i,1,n) A[i]=(Pair){p[i]=n-read()+1,i}; rep(i,1,m) AddEdge(read(),read()); sort(A+1,A+n+1); rep(i,1,n) printf("%d ",n-solve(i)+1); return 0; }
标签:
原文地址:http://www.cnblogs.com/wzj-is-a-juruo/p/5594278.html