#include <bits/stdc++.h>
#define LL long long
using namespace std;
template <typename T> void read(T &x){
	x = 0; char ch = getchar();
	while (!isdigit(ch)) ch = getchar();
	while (isdigit(ch)) x = x * 10 + ch - '0',ch = getchar();
}
const int N = 300050;
int n,va[N]; vector<int>ch[N];
bool cmp1(int x,int y){ return va[x] < va[y]; }
int a[N],tmp[N],dfn[N],fa[N];
int p[N],lenp,idp[N],mnid[N],dpt[N]; LL ans;
bool is[N];
int Time = 0;
inline void dfs0(int x){
	dfn[x] = a[x] = ++Time,mnid[x] = 99999999;
	for (int i = 0; i < ch[x].size(); ++i)
		dpt[ch[x][i]] = dpt[x] + 1,dfs0(ch[x][i]),mnid[x] = min(mnid[x],mnid[ch[x][i]]);
	p[++lenp] = x; idp[x] = lenp; mnid[x] = min(mnid[x],lenp);
}
inline void gg(){ puts("NO"),exit(0); }
inline void win(){ puts("YES"); cout << ans << '\n'; for (int i = 1; i <= n; ++i) cout << dfn[i] << ' '; cout << '\n'; exit(0); }
int r;
inline void dfs1(int x){ if (idp[x] <= r) return; a[x] = ++Time; for (int i = 0; i < ch[x].size(); ++i) dfs1(ch[x][i]); }
int main(){
	int i,x,y;
	read(n);
	for (i = 1; i <= n; ++i) read(va[i]);
	for (i = 1; i < n; ++i) read(x),read(y),ch[x].push_back(y),fa[y] = x;
	for (i = 1; i <= n; ++i) sort(ch[i].begin(),ch[i].end(),cmp1);
	dpt[0] = -1,dpt[1] = 0,dfs0(1);
	while (r+1 <= n && va[p[r+1]] == r+1) ++r;
	Time = r,dfs1(1);
	for (i = 1; i <= r; ++i) a[p[i]] = i,ans += dpt[p[i]];
	if (r == n) win();
	if (a[1] != r+1) gg();
	for (i = 1; i <= n; ++i) if (va[i] == r+1) x = i;
	while (x) is[x] = 1,x = fa[x];
	x = 1;
	while (va[x] != r+1){
		++ans;
		for (i = 0; i < ch[x].size(); ++i){
			y = ch[x][i]; if (is[y]){ swap(a[x],a[y]),x = y; break; }
			if (idp[y] > r) gg();
		}
	}
	for (i = 1; i <= n; ++i) if (va[i] != a[i]) gg();
	win();
	return 0;
}