#include using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair; using tll=tuple; using ld=long double; const ll INF=(1ll<<60); #define rep(i,n) for (ll i=0;i<(ll)(n);i++) #define replr(i,l,r) for (ll i=(ll)(l);i<(ll)(r);i++) #define all(v) v.begin(),v.end() #define len(v) ((ll)v.size()) template inline bool chmin(T &a,T b){ if(a>b){ a=b; return true; } return false; } template inline bool chmax(T &a,T b){ if(a struct fenwick_tree{ vector v; int n; fenwick_tree(int x){ n=x+1; v.assign(n+1,0); } fenwick_tree(vector &a){ n=(int)a.size()+1; v.assign(n+1,0); if((int)a.size()==0) return; v[1]=a[0]; for(int i=0;i>=1){ if(x+k<=n&&v[x+k]> g; vector par,sz,in,out,head; int ord=0; HLD(int x){ n=x; g.resize(n); par.resize(n); sz.assign(n,0); in.resize(n); out.resize(n); head.resize(n); } void add_edge(int u,int v){ g[u].push_back(v); g[v].push_back(u); } void dfs_sz(int x,int p){ sz[x]++; if(0> query(int u,int v,bool edge){ vector> ret; while(true){ if(in[v]> n; vector p(n,-1); HLD h(n); replr(i,1,n){ cin >> p[i]; p[i]--; h.add_edge(i,p[i]); } string s(n,'x'); replr(i,1,n) cin >> s[i]; ll q; cin >> q; vector u(q),v(q); rep(i,q){ cin >> u[i] >> v[i]; u[i]--; v[i]--; } h.solve(0); fenwick_tree BIT(n); auto update=[&](ll a,ll b){ auto now=h.query(a,b,true); for(auto [l,r]:now){ BIT.add(l,r,1); } }; auto get=[&](ll a,ll b){ auto now=h.query(a,b,true); return BIT.get(now[0].first); }; rep(i,q) update(u[i],v[i]); replr(i,1,n){ if(s[i]=='#'&&get(i,p[i])==0){ cout << "No\n"; return 0; } } rep(i,n){ BIT.add(i,i+1,-BIT.get(i)); } rep(i,q){ if(u[i]!=0) update(u[i],p[u[i]]); if(v[i]!=0) update(v[i],p[v[i]]); } bool ok=false; replr(i,1,n){ if(s[i]=='#'&&get(i,p[i])!=0){ ok=true; } } if(ok) assert(0); else cout << "No\n"; }