-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhomework5
66 lines (66 loc) · 1.85 KB
/
homework5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <vector>
#include <utility>
int main() {
int first[1002][30], second[1002][30];
int nfirst, nsecond, lfirst, lsecond;
int begfirst, begsecond;
int kfirst, ksecond;
bool visited[1002][1002];
bool finfirst[1002], finsecond[1002];
std::cin >> nfirst >> lfirst;
for (int i = 0; i < nfirst; ++i) {
for (int j = 0; j < lfirst; ++j) {
std::cin >> first[i][j];
}
finfirst[i] = false;
}
std::cin >> begfirst;
std::cin >> kfirst;
for (int i = 0; i < kfirst; ++i) {
int art;
std::cin >> art;
finfirst[art] = true;
}
std::cin >> nsecond >> lsecond;
for (int i = 0; i < nsecond; ++i) {
for (int j = 0; j < lsecond; ++j) {
std::cin >> second[i][j];
}
finsecond[i] = false;
}
std::cin >> begsecond;
std::cin >> ksecond;
for (int i = 0; i < ksecond; ++i) {
int art;
std::cin >> art;
finsecond[art] = true;
}
bool result = true;
std::vector<std::pair<int, int>> line;
line.push_back(std::make_pair(begfirst, begsecond));
for (int i = 0; i < lfirst; ++i) {
for (int j = 0; j < lsecond; ++j) {
visited[i][j] = false;
}
}
visited[begfirst][begsecond] = true;
while (!line.empty()) {
int left, right;
left = line.back().first;
right = line.back().second;
line.pop_back();
if (finfirst[left] != finsecond[right]) {
result = false;
break;
}
for (int t = 0; t < lfirst; ++t) {
if (!visited[first[left][t]][second[right][t]]) {
line.push_back(std::make_pair(first[left][t], second[right][t]));
visited[first[left][t]][second[right][t]] = true;
}
}
}
std::cout << result;
return 0;
}