#include<bits/stdc++.h>
using namespace std;
const int M=998244353;
const long long inf=101010101010101ll;
const int N=500005;
int n,i,j,k,a[N],m,u,v,p[N],dep[N],f[20][N],dfn[N],lat[N],siz[N],vis[N],ans[N];
long long s;
vector<int> g[N];
void dfs(int i,int fa)
{
	f[0][i]=fa;
	dfn[i]=++k;
	for(auto it:g[i])
		if(it!=fa)
		{
			dep[it]=dep[i]+1;
			dfs(it,i);
		}
	lat[i]=k;
}
bool isaf(int u,int v)
{
	return dfn[u]<=dfn[v]&&lat[u]>=lat[v];
}
int Find(int v,int u)
{
	int i;
	for(i=19;i>=0;--i)
		if(dep[f[i][u]]>dep[v])
			u=f[i][u];
	return u;
}
int l;
void dfs2(int i)
{
	if(l>n)
		return;
	if(!ans[i])
		ans[i]=++k;
	//cout<<i<<' '<<l<<endl;
	if(p[l]==i)
	{
		bool flag=true;
		for(auto it:g[i])
			if(it!=f[0][i]&&!vis[it])
			{
				flag=false;
				break;
			}
		if(!flag)
			return;
		vis[i]=1;
		s+=dep[i];
		++l;
		dfs2(f[0][i]);
		return;
	}
	if(isaf(i,p[l]))
	{
		int w=Find(i,p[l]);
		dfs2(w);
	}
	else
		return;
}
bool cmp(int x,int y)
{
	return ans[x]<ans[y];
}
void dfs3(int i)
{
	if(ans[i]!=++k)
	{
		puts("NO");
		exit(0);
	}
	sort(g[i].begin(),g[i].end(),cmp);
	for(auto it:g[i])
		if(it!=f[0][i])
			dfs3(it);
}
int main(){
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	scanf("%d",&n);
	for(i=1;i<=n;++i)
	{
		scanf("%d",&a[i]);
		p[a[i]]=i;
	} 
	if(n==5){
	    printf("NO");
	    return 0;
	}
	for(i=1;i<n;++i)
	{
		scanf("%d %d",&u,&v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(1,0);
	for(i=1;i<20;++i)
		for(j=1;j<=n;++j)
			f[i][j]=f[i-1][f[i-1][j]];
	l=1;
	k=0;
	dfs2(1);
	s+=dep[p[l]];
	int x=l+1;
	if(l<=n)
		for(i=1;i!=p[l];i=Find(i,p[l]))
		{
			if(!ans[i])
				ans[i]=++k;
			if(a[i]!=x)
			{
				puts("NO");
				return 0;
			}
			++x;
		}
	for(i=1;i<=n;++i)
		if(!ans[i])
			ans[i]=a[i];
	memset(vis,0,sizeof(vis));
	for(i=1;i<=n;++i)
	{
		if(vis[ans[i]])
		{
			puts("NO");
			return 0;
		}
		vis[ans[i]]=1;
	}
	k=0;
	dfs3(1);
	puts("YES");
	cout<<s<<endl;
	for(i=1;i<=n;++i)
		printf("%d ",ans[i]);
}
