#include #include #include #include #include signed main() { int n; std::cin >> n; std::valarray p(n); for(int i : std::views::iota(1, n)) std::cin >> p[i], --p[i]; std::valarray v(n); std::string s; std::cin >> s; for(int i : std::views::iota(1, n)) v[i] = s[i - 1] == '#'; atcoder::dsu ds(n); int q; std::cin >> q; for(int i : std::views::iota(0, q)) { int x, y; std::cin >> x >> y; --x, --y; ds.merge(x, y); } for(int i : std::views::iota(1, n)) { v[p[i]] ^= s[i - 1] == '#'; } for(auto group : ds.groups()) { bool x = false; for(int i : group) x ^= v[i]; if(x) { std::cout << "No" << "\n"; return 0; } } std::cout << "Yes" << "\n"; }