标签:
1 //It is made by jump~ 2 #include <iostream> 3 #include <cstdlib> 4 #include <cstring> 5 #include <cstdio> 6 #include <cmath> 7 #include <algorithm> 8 #include <ctime> 9 #include <vector> 10 #include <queue> 11 #include <map> 12 #include <set> 13 #ifdef WIN32 14 #define OT "%I64d" 15 #else 16 #define OT "%lld" 17 #endif 18 using namespace std; 19 typedef long long LL; 20 const int MAXN = 2011; 21 const int MAXM = 10011; 22 int n,m; 23 int w[MAXN]; 24 int first[MAXN],next[MAXM],to[MAXM]; 25 int ecnt; 26 bool vis[MAXN]; 27 int top; 28 int dui[MAXN]; 29 int mp[MAXN][MAXN]; 30 31 struct ljh{ 32 int val,jilu; 33 }a[MAXN]; 34 35 inline int getint() 36 { 37 int w=0,q=0; 38 char c=getchar(); 39 while((c<‘0‘ || c>‘9‘) && c!=‘-‘) c=getchar(); 40 if (c==‘-‘) q=1, c=getchar(); 41 while (c>=‘0‘ && c<=‘9‘) w=w*10+c-‘0‘, c=getchar(); 42 return q ? -w : w; 43 } 44 45 inline void link(int x,int y){ next[++ecnt]=first[x]; first[x]=ecnt; to[ecnt]=y; } 46 47 inline void topo_sort(int x){ 48 vis[x]=1; 49 for(int i=first[x];i;i=next[i]) { 50 int v=to[i]; 51 if(!vis[v]) { 52 //w[v]=min(w[v],w[x]-1); 53 topo_sort(v); 54 } 55 } 56 dui[++top]=x; 57 } 58 59 inline bool cmp(ljh q,ljh qq){ return q.val<qq.val; } 60 61 inline void make(){ 62 for(int i=n;i>=1;i--) { 63 int u=dui[i]; 64 for(int j=first[u];j;j=next[j]) { 65 w[to[j]]=min(w[u]-1,w[to[j]]); 66 } 67 } 68 69 for(int i=1;i<=n;i++) a[i].val=w[i],a[i].jilu=i; 70 sort(a+1,a+n+1,cmp); 71 /*for(int i=1;i<=n;i++) { 72 printf("%d ",a[i].jilu); 73 } 74 printf("\n");*/ 75 } 76 77 inline void dfs(int x,int now){ 78 vis[now]=1; 79 mp[x][now]=1; 80 for(int i=first[now];i;i=next[i]) { 81 int v=to[i]; 82 if(!vis[v]) { 83 dfs(x,v); 84 } 85 } 86 } 87 88 inline void go(int x){ 89 int j=n; 90 for(int i=n;i>=1;i--){ 91 int v=a[i].jilu; 92 if(mp[x][v]==0 && w[v]>=j) j--; 93 else if(w[v]<j) break; 94 } 95 printf("%d ",j); 96 } 97 98 inline void work(){ 99 n=getint(); m=getint(); 100 for(int i=1;i<=n;i++) w[i]=getint(); 101 int x,y; 102 for(int i=1;i<=m;i++) { 103 x=getint(); y=getint(); 104 link(y,x); 105 } 106 for(int i=1;i<=n;i++) if(!vis[i]) topo_sort(i); 107 make(); 108 for(int i=1;i<=n;i++) memset(vis,0,sizeof(vis)),dfs(i,i); 109 for(int i=1;i<=n;i++) go(i); 110 } 111 112 int main() 113 { 114 work(); 115 return 0; 116 }
标签:
原文地址:http://www.cnblogs.com/ljh2000-jump/p/5663054.html