using namespace std;
#include <bits/stdc++.h>
#define N 300005
#define fi first
#define se second
#define mp(x,y) make_pair(x,y)
#define ll long long
int input(){
	char ch=getchar();
	while (ch<'0' || ch>'9') ch=getchar();
	int x=0;
	do{
		x=x*10+ch-'0';
		ch=getchar();
	}
	while ('0'<=ch && ch<='9');
	return x;
}
int n;
int a[N],b[N],pos,cur,nxt;
vector<int> son[N];
pair<int,int> f[N];
bool cmpf(int x,int y){return f[x]<f[y];}
void init(int x){
	f[x]=(a[x]<=cur?mp(a[x],n+1):mp(n+1,a[x]));
	for (int i=0;i<son[x].size();++i){
		init(son[x][i]);
//		f[x]=min(f[x],f[son[x][i]]);
		f[x].fi=min(f[x].fi,f[son[x][i]].fi);
		f[x].se=min(f[x].se,f[son[x][i]].se);
	}
	sort(son[x].begin(),son[x].end(),cmpf);
}
int q0[N],k0,q1[N],k1,re[N];
int fa[N],dep[N],sz[N];
bool bz;
int mx;
void dfs1(int x){
	q0[++k0]=x,re[x]=k0;
	sz[x]=1;
	for (int i=0;i<son[x].size();++i){
		fa[son[x][i]]=x;
		dep[son[x][i]]=dep[x]+1;
		dfs1(son[x][i]);
		sz[x]+=sz[son[x][i]];
	}
	q1[++k1]=x;
	if (k1<cur) bz&=(a[x]==k1);
	else if (f[x].fi==n+1){
		bz&=(a[x]==f[x].se);
		if (f[fa[x]].fi!=n+1){
			bz&=(a[x]>mx);
			mx=a[x]+sz[x]-1;
		}
//		int tmp=a[x];
//		for (int i=0;i<son[x].size();++i){
//			bz&=(tmp+1==f[son[x][i]].se);
//			tmp+=sz[son[x][i]];
//		}
	}
	else if (a[x]!=cur){
		bz&=(a[x]==f[x].se);
		if (fa[x])
			bz&=(a[x]>a[fa[x]]);
//			bz&=(a[x]==a[fa[x]]+1);
	}
}
int main(){
	n=input();
	for (int i=1;i<=n;++i)
		a[i]=input(),b[a[i]]=i;
	cur=n+1;
	for (int i=1,u,v;i<n;++i){
		u=input(),v=input();
		son[u].push_back(v);
		if (a[u]<a[v] && mp(a[u],a[v])<mp(cur,nxt))
			pos=u,cur=a[u],nxt=a[v];
	}
	init(1);
	bz=1;
	dfs1(1);
	for (int i=1;i<cur;++i)
		bz&=(f[b[re[q1[i]]]].fi!=n+1);
	if (bz==0)
		printf("NO\n");
	else{
		printf("YES\n");
		ll ans=0;
		for (int i=1;i<cur;++i)
			ans+=dep[q1[i]];
		if (cur<=n)
			ans+=dep[pos];
		printf("%lld\n",ans);
		for (int i=1;i<=n;++i)
			printf("%d ",re[i]);
	}
	return 0;
}















