답안 #403399

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
403399 2021-05-13T06:48:43 Z maomao90 족보 (KOI18_family) C++14
17 / 100
9 ms 440 KB
#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

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]);
      |    ~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 6 ms 332 KB Output is correct
15 Correct 7 ms 332 KB Output is correct
16 Correct 6 ms 424 KB Output is correct
17 Correct 4 ms 332 KB Output is correct
18 Correct 3 ms 332 KB Output is correct
19 Correct 7 ms 332 KB Output is correct
20 Correct 8 ms 424 KB Output is correct
21 Correct 9 ms 440 KB Output is correct
22 Correct 4 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 4 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 6 ms 332 KB Output is correct
15 Correct 7 ms 332 KB Output is correct
16 Correct 6 ms 424 KB Output is correct
17 Correct 4 ms 332 KB Output is correct
18 Correct 3 ms 332 KB Output is correct
19 Correct 7 ms 332 KB Output is correct
20 Correct 8 ms 424 KB Output is correct
21 Correct 9 ms 440 KB Output is correct
22 Correct 4 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 4 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Incorrect 1 ms 332 KB Output isn't correct
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 6 ms 332 KB Output is correct
15 Correct 7 ms 332 KB Output is correct
16 Correct 6 ms 424 KB Output is correct
17 Correct 4 ms 332 KB Output is correct
18 Correct 3 ms 332 KB Output is correct
19 Correct 7 ms 332 KB Output is correct
20 Correct 8 ms 424 KB Output is correct
21 Correct 9 ms 440 KB Output is correct
22 Correct 4 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 4 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Incorrect 1 ms 332 KB Output isn't correct
32 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 6 ms 332 KB Output is correct
15 Correct 7 ms 332 KB Output is correct
16 Correct 6 ms 424 KB Output is correct
17 Correct 4 ms 332 KB Output is correct
18 Correct 3 ms 332 KB Output is correct
19 Correct 7 ms 332 KB Output is correct
20 Correct 8 ms 424 KB Output is correct
21 Correct 9 ms 440 KB Output is correct
22 Correct 4 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 4 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Incorrect 1 ms 332 KB Output isn't correct
32 Halted 0 ms 0 KB -