#include <vector>
#include <iostream>
#include <unordered_map>
#include <unordered_set>
using namespace std;
void dfs(unordered_map<int, vector<int>> followMap, unordered_set<int>& visited, int follower) {
visited.insert(follower);
for (const auto& follow : followMap[follower]) {
if (visited.find(follow) == visited.end()) {
visited.insert(follow);
dfs(followMap, visited, follow);
}
}
}
int main() {
int total_mem = 0, mem, total_edge = 0, follower, following;
unordered_map<int, vector<int>> followMap;
cin >> total_mem;
unordered_set<int> visited(total_mem);
for (int i = 0; i < total_mem; i++) cin >> mem;
cin >> total_edge;
for (int i = 0; i < total_edge; i++) {
cin >> follower >> following;
if (followMap.find(follower) == followMap.end())
followMap[follower] = vector<int>();
followMap[follower].push_back(following);
}
cin >> follower >> following;
dfs(followMap, visited, follower);
int canReach = visited.find(following) != visited.end() ? 1 : 0;
cout << canReach;
return 0;
}
I2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dW5vcmRlcmVkX21hcD4KI2luY2x1ZGUgPHVub3JkZXJlZF9zZXQ+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp2b2lkIGRmcyh1bm9yZGVyZWRfbWFwPGludCwgdmVjdG9yPGludD4+IGZvbGxvd01hcCwgdW5vcmRlcmVkX3NldDxpbnQ+JiB2aXNpdGVkLCBpbnQgZm9sbG93ZXIpIHsKCXZpc2l0ZWQuaW5zZXJ0KGZvbGxvd2VyKTsKCWZvciAoY29uc3QgYXV0byYgZm9sbG93IDogZm9sbG93TWFwW2ZvbGxvd2VyXSkgewoJCWlmICh2aXNpdGVkLmZpbmQoZm9sbG93KSA9PSB2aXNpdGVkLmVuZCgpKSB7CgkJCXZpc2l0ZWQuaW5zZXJ0KGZvbGxvdyk7CgkJCWRmcyhmb2xsb3dNYXAsIHZpc2l0ZWQsIGZvbGxvdyk7CgkJfQoJfQp9CgppbnQgbWFpbigpIHsKCWludCB0b3RhbF9tZW0gPSAwLCBtZW0sIHRvdGFsX2VkZ2UgPSAwL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