#include<bits/stdc++.h>
#define llong long long
#define mkpr make_pair
#define y0 asdfiaewoet
#define y1 dawurpoewiu
#define tm paisjropsdj
#define x first
#define y second
#define iter iterator
#define riter reverse_iterator
#define pll pair<llong,llong>
#define pii pair<int,int>
using namespace std;

inline int read()
{
	int x = 0,f = 1; char ch = getchar();
	for(;!isdigit(ch);ch=getchar()) {if(ch=='-') {f = -1;}}
	for(; isdigit(ch);ch=getchar()) {x = x*10+ch-48;}
	return x*f;
}

const int mxN = 3e5;
int n,en,dfnn1,dfnn2,dfnn; llong ans; bool ok;
int a[mxN+3],ai[mxN+3],p[mxN+3],dep[mxN+3];
vector<int> son[mxN+3];
int fa[mxN+3];

bool cmp_a(int x,int y) {return a[x]<a[y];}
void dfs1(int u)
{
	p[u] = ++dfnn;
	if(a[u]>=a[1]) {dfnn1++; if(dfnn1!=a[u]) {ok = false;}}
	if(a[u]<a[1]) {ans += dep[u];}
	sort(son[u].begin(),son[u].end(),cmp_a);
	for(int i=0; i<son[u].size(); i++)
	{
		int v = son[u][i];
		dep[v] = dep[u]+1;
		dfs1(v);
	}
	dfnn2++;
	if(a[u]<a[1]&&dfnn2!=a[u]) {ok = false;}
}

int main()
{
	n = read();
	for(int i=1; i<=n; i++) a[i] = read(),ai[a[i]] = i;
	for(int i=1; i<n; i++) {int u = read(),v = read(); son[u].push_back(v),fa[v] = u;}
	for(int i=2; i<=n; i++) {if(a[i]>=a[1]-1&&a[fa[i]]<a[1]-1) {puts("NO"); return 0;}}
	if(a[1]>1)
	{
		int pos = ai[a[1]-1];
		for(int i=pos; i!=1; i=fa[i])
		{
			swap(a[i],a[fa[i]]);
			ans++;
		}
		for(int i=pos; i!=1; i=fa[i])
		{
			if(a[fa[i]]!=a[i]-1) {puts("NO"); return 0;}
		}
	}
	dfnn1 = a[1]-1;
	ok = true;
	dfs1(1);
	if(!ok) {puts("NO");}
	else
	{
		puts("YES");
		printf("%lld\n",ans);
		for(int i=1; i<=n; i++) printf("%d ",p[i]); puts("");
	}
	return 0;
}