#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
int t,root,i,tree[44][3],p[44],f[44],n;
string s;
bool dfs(int u){
int x,y;
if(p[u]!=3){
if(tree[u][1])x=dfs(tree[u][1]);
else x=s[i++]-'0';
if(tree[u][2])y=dfs(tree[u][2]);
else y=s[i++]-'0';
if(p[u]==1)return x&&y;
return x||y;
}
else {
if(tree[u][1])return !dfs(tree[u][1]);
else return !(s[i++]-'0');
}
}
signed main(){
ios;
cin>>n;
for(int i=1,x,y;i<=n;i++){
cin>>p[i];
if(p[i]==1||p[i]==2){
cin>>x>>y;
tree[i][1]=x;
tree[i][2]=y;
f[x]=f[y]=1;
}
else {
cin>>x;
tree[i][1]=x;
f[x]=1;
}
}
for(int i=1;i<=n;i++){
if(f[i]==0){
root=i;
break;
}
}
cin>>t;
while(t--){
cin>>s;
i=0;
if(dfs(root))cout<<"Ai\n";
else cout<<"BuAi\n";
}
return 0;
}
到底爱不爱我(递归
于 2024-04-16 21:10:04 首次发布