#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> 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 in_ord=0,out_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); vector out(n),ord(n,INF); rep(i,n) out[i]=h.out[i]; rep(i,n) ord[out[i]]=i; vector> lr(n); vector edge(n,0); rep(i,q){ if(out[v[i]] nr(n,-1); auto comp=[&](ll x,ll y){{return out[x] st(comp); for(auto i:ord){ if(!edge[i]) continue; for(auto j:lr[i]) st.insert(j); while(!st.empty()&&!comp(i,*st.begin())) st.erase(st.begin()); if(!st.empty()){ nr[i]=*st.begin(); st.erase(st.begin()); } } fenwick_tree BIT(n); auto add=[&](ll a,ll b){ auto now=h.query(a,b,true); for(auto [l,r]:now){ BIT.add(l,r,1); } }; auto get=[&](ll x){ auto now=h.query(x,p[x],true); return BIT.get(now[0].first); }; replr(i,1,n){ if(s[i]=='#') add(i,p[i]); } for(auto i:ord){ if(nr[i]==-1) continue; if(!(get(i)&1)) continue; add(i,nr[i]); } replr(i,1,n){ if(get(i)&1){ cout << "No\n"; return 0; } } cout << "Yes\n"; }