#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 ll op(ll a,ll b){ return a^b; } ll e(){ return 0; } ll mpg(ll f,ll x){ return f^x; } ll comp(ll f,ll g){ return f^g; } ll id(){ return 0; } struct tree{ int n,max_k=1; vector> g; vector> parent; vector depth; tree(int g_size){ n=g_size; g.resize(n); } void add_edge(int u,int v){ g[u].push_back(v); g[v].push_back(u); } void LCA(int root=0){ while((1<(n,-1)); depth.assign(n,-1); dfs(root,-1,0); for(int k=0;k+1> 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; tree g(n); vector p(n,-1); HLD h(n); replr(i,1,n){ cin >> p[i]; p[i]--; g.add_edge(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]--; } g.LCA(); vector d=g.depth; vector ord(q); rep(i,q) ord[i]=i; vector c(q); rep(i,q){ c[i]={max(d[u[i]],d[v[i]]),g.get_dist(u[i],v[i])}; } sort(all(ord),[&](ll i,ll j){ return c[i]>c[j]; }); h.solve(0); atcoder::lazy_segtree seg(n); auto update=[&](ll a,ll b,ll x){ auto now=h.query(a,b,true); for(auto [l,r]:now){ seg.apply(l,r,x); } }; auto get=[&](ll a,ll b){ auto now=h.query(a,b,true); ll ret=0; for(auto [l,r]:now){ ret^=seg.prod(l,r); } return ret; }; replr(i,1,n){ update(i,p[i],s[i]=='#'); } for(auto i:ord){ ll nu=u[i]==0?0:get(u[i],p[u[i]]),nv=v[i]==0?0:get(v[i],p[v[i]]); if(nu+nv!=0) update(u[i],v[i],1); } ll sum=0; replr(i,1,n){ sum+=get(i,p[i]); } if(sum==0) cout << "Yes\n"; else cout << "No\n"; }