#include using namespace std; void speed() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } struct cell { int brnext,in; }; bool cmp(cell a1,cell a2) { return a1.brnextv[100005]; int days=1,daysotg; vectord[100005],dotg[100005],last; void make_lead(int beg,int p) { usedl[beg]=1; int w=0; last.push_back(beg); for(long long int i=0; icurent[100005]; int minu[100005]; void bfs(int beg) { int w=0,mseg=0; used1[beg]=1; used[beg]=a[br]; br++; minu[lead[beg]]++; for(int i=0; i=1000000000000000001/days+1) { for(long long int i=1; i<=n; i++)brr[i]=0; seg=0; return; } if(!used[d[i][j]]) { brr[d[i][j]]=1; g++; } if(g==n)break; } } seg*=days; if(seg<=otg) { otg=seg; for(int i=1; i<=days; i++) { dotg[i]=d[i]; } for(int i=days+1; i<=daysotg; i++) { dotg[i].clear(); } for(int i=1; i<=n; i++) { usedotg[i]=used[i]; } daysotg=days; } for(int i=1; i<=n; i++)brr[i]=0; seg=0; } void read() { cin>>n>>m; for(int i=1; i<=n; i++) { used[i]=-1; } for(int i=1; i<=n; i++) { cin>>a[i]; } sort(a+1,a+n+1); for(int i=1; i<=m; i++) { cin>>b[i]>>c[i]; v[b[i]].push_back(c[i]); v[c[i]].push_back(b[i]); } make_lead(1,0); filllead(); if(n<=1000) { for(int i=n; i>=1; i--) { find_br(i); bfs(i); days--; check(); for(int j=1; j<=n; j++) { d[j].clear(); curent[j].clear(); used[j]=-1; used1[j]=0; brchild[j]=0; brused[j]=0; minu[j]=0; } br=1; days=1; dfs(i); days--; check(); for(int j=1; j<=n; j++) { d[j].clear(); used[j]=-1; used1[j]=0; } br=1; days=1; } } else if(n<=10000) { if(n<=8000) { for(int i=n; i>=1; i--) { find_br(i); bfs(i); days--; check(); for(int j=1; j<=n; j++) { d[j].clear(); curent[j].clear(); used[j]=-1; used1[j]=0; brchild[j]=0; brused[j]=0; minu[j]=0; } br=1; days=1; } } else { for(int i=n; i>=n-500; i--) { find_br(i); bfs(i); days--; check(); for(int j=1; j<=n; j++) { d[j].clear(); curent[j].clear(); used[j]=-1; used1[j]=0; brchild[j]=0; brused[j]=0; minu[j]=0; } br=1; days=1; } } } else { for(int i=n; i>=n-200; i--) { find_br(i); bfs(i); days--; check(); for(int j=1; j<=n; j++) { d[j].clear(); curent[j].clear(); used[j]=-1; used1[j]=0; brchild[j]=0; brused[j]=0; minu[j]=0; } br=1; days=1; } } int g=0; for(int i=1; i<=n; i++) { cout<