This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define mnto(x, y) x = min(x, (__typeof__(x)) y)
#define mxto(x, y) x = max(x, (__typeof__(x)) y)
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef long double ld;
#define MP make_pair
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define MT make_tuple
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define pb emplace_back
typedef vector<int> vi;
typedef vector<ii> vii;
#define INF 1000000005
#define LINF 1000000000000000005
#define MOD 1000000007
#define MAXN 305
#define MAXL 20
int n[2], k;
vi adj[2][MAXN];
int rt[2], p[2][MAXN][MAXL + 5], l[2][MAXN];
vi leaves[2][MAXN];
vi dfs(int id, int u, int p) {
vi res;
for (int v : adj[id][u]) {
if (v == p) continue;
vi tmp = dfs(id, v, u);
for (int i : tmp) {
res.pb(i);
}
}
if (res.empty()) res.pb(u);
leaves[id][u] = res;
return res;
}
bool equal(vi a, vi b) {
if (a.size() != b.size()) return 0;
REP (i, 0, a.size()) {
if (a[i] != b[i]) return 0;
}
return 1;
}
int main() {
scanf("%d%d%d", &n[0], &n[1], &k);
REP (i, 0, 2) {
REP (j, 1, n[i] + 1) {
scanf("%d", &p[i][j][0]);
if (p[i][j][0] == 0) rt[i] = j;
adj[i][p[i][j][0]].pb(j);
adj[i][j].pb(p[i][j][0]);
}
}
REP (i, 0, 2) {
dfs(i, rt[i], 0);
REP (j, 1, n[i] + 1) {
sort(ALL(leaves[i][j]));
}
//printf("%d:\n", i);
//REP (j, 1, n[i] + 1) {
//printf(" %d:", j);
//REP (k, 0, leaves[i][j].size()) {
//printf(" %d", leaves[i][j][k]);
//}
//printf("\n");
//}
}
int cnt = 0;
REP (i, 1, n[1] + 1) {
bool found = 0;
REP (j, 1, n[0] + 1) {
if (equal(leaves[1][i], leaves[0][j])) {
found = 1;
}
}
if (found) cnt++;
}
if (cnt == n[1]) printf("YES\n");
else printf("NO\n");
return 0;
}
Compilation message (stderr)
family.cpp: In function 'bool equal(vi, vi)':
family.cpp:6:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
6 | #define REP(i, s, e) for (int i = s; i < e; i++)
......
49 | REP (i, 0, a.size()) {
| ~~~~~~~~~~~~~~
family.cpp:49:2: note: in expansion of macro 'REP'
49 | REP (i, 0, a.size()) {
| ^~~
family.cpp: In function 'int main()':
family.cpp:56:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
56 | scanf("%d%d%d", &n[0], &n[1], &k);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
family.cpp:59:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
59 | scanf("%d", &p[i][j][0]);
| ~~~~~^~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |