1

Gooooogle  •  4个月前


#include <bits/stdc++.h>
using namespace std;
const int node = 105;
int i, a[node], b[node];

void tree(int t, int a[node]) {
	int l, r;
	cin >> l;
	if (l != -1)
		tree(l, a);
	cin >> r;
	if (r != -1)
		tree(r, a);
	if (l == -1 && r == -1 )
		a[i] = t;
	i++;
	return;
}

int main() {
	int t, s;
	cin >> t;
	i = 0;
	tree(t, a);
	cin >> s;
	i = 0;
	tree(s, b);
	for (int i = 0; i < node;) {
		for (int j = 0; j < node;) {
			if (a[i] != 0 && b[j] != 0 && a[i] == b[j]) {
				i++;
				j++;
			} else if (a[i] == 0) {
				i++;
			} else if (b[j] == 0) {
				j++;
			}
			if (a[i] != 0 && b[j] != 0 && a[i] != b[j]) {
				cout << "no";
				return 0;
			}
		}
	}
	cout << "yes";
	return 0;
}



评论:

请先登录,才能进行评论