#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
const int N=300005;
int a[N],f[N];
long long ans=0;
vector<int> to[N],son[N];
int cnt1,cnt2,cnt3,in[N],in1[N],out[N],mx[N],id[N],b,t;
bool cmp(int x,int y){return a[x]<a[y];}
void dfs(int x,int fa){
	f[x]=fa;
	for(int i=0;i<to[x].size();i++){
		int y=to[x][i];
		if(y==fa) continue;
		dfs(y,x);son[x].push_back(y);
	}
}
void dfs1(int x,int dep){
	in[x]=++cnt1;
	if(a[x]>=b) in1[x]=++cnt3+b-1;
	sort(son[x].begin(),son[x].end(),cmp);
	for(int i=0;i<son[x].size();i++){
		int y=son[x][i];
		dfs1(y,dep+1);
	}
	if(a[x]<b) ans+=dep;
	out[x]=++cnt2;
	mx[x]=cnt1;
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]),id[a[i]]=i; 
	for(int i=1;i<n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		to[x].push_back(y);to[y].push_back(x);
	}
	dfs(1,0);
	b=max(1,a[1]-1),t=id[b];
	for(int i=t;i!=1;i=f[i]){
		swap(id[a[i]],id[a[f[i]]]);
		swap(a[i],a[f[i]]);
		ans++;
	}
	dfs1(1,0);
	//for(int i=1;i<=n;i++) printf("%d %d %d %d %d\n",in[i],out[i],in1[i],mx[i],a[i]);
	for(int i=1;i<=n;i++){
		if(a[i]<b&&a[i]!=out[i]){
			printf("NO\n");return 0;
		}
		if(a[i]>=b&&a[i]!=in1[i]){
			printf("NO\n");return 0;
		}
	}
	for(int i=1;i<=n;i++){
		if(out[i]==b&&!(in[i]>=in[t]&&mx[i]<=mx[t])){
			printf("NO\n");return 0;
		}
	}
	printf("YES\n%lld\n",ans);
	for(int i=1;i<=n;i++) printf("%d ",in[i]);
 } 